Question

important don't use arrays or listed pleaseeeee

in python 3 Write a program that given a collection of ?N numbers will find the largest value, its frequency and the average of the ?N numbers.

  • Get the value of ?N from the user.

  • If ?≤0N≤0, display an appropriate error message and terminate the program; otherwise

  • Read the values as entered from the user. (If ?=5N=5, then there are 5 values the user is going to enter).

  • Find the largest, its frequency (how many times it is repeated) and the average of these ?N values.

  • Hint: To find the largest value, read the first value before the loop then assume that this first value entered by the user is the largest value. Within the loop compare the assumed largest value with other values read inside the loop and change the largest value accordingly.Sample Runs Enter how many values to consider: -2 Wrong input. Input must be > 0 Enter how many values to consider: 4 Enter v

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello there. I hope you are fine.

Here is the Python code you need.

# import exit function
# we will use this to exit if user enters value of N less than 0
from sys import exit

# ask the user how many values to consider
N = int(input('Enter how many values to consider: '))

# check if N is less than 1
if N < 1:
    # if it is, print the message and exit with exit code 1
    print('Wrong input. Input must be > 0')
    exit(1)

# if N is not less than 1
# ask the user the very first value out of N values
num = int(input('Enter value 1: '))

# initialize maximum with the currently entered value
maximum = num

# initialize count to be 1
# assuming the currently entered number is the maximum
count = 1

# initialize total to be equal to num
# we will add to total in every iteration of for loop
# this is done to calculate average
total = num

# ask the remaining values from the user
for i in range(1, N):
    # get the input in input_num
    input_num = int(input('Enter value %d: ' % (i + 1)))
    # add it to total
    total += input_num
    # check if input_num is more than current maximum
    # if it is, set maximum to input_num
    # and set count to 1
    if input_num > maximum:
        maximum = input_num
        count = 1
    # if input_num is equal to maximum
    # increment count by 1
    elif input_num == maximum:
        count += 1

# calculate average
# it will be total divided by N (total values considered)
average = total / N

# print the maximum value
print('Maximum value = %d' % maximum)
# print its count
print("It's frequency is %d" % count)
# print the average, rounded to 2 decimal places
print('Average = %.2f' % average)

code snapshot:
from sys import exit N = int(input(Enter how many values to consider: )) if N < 1: print(Wrong input. Input must be > 0)

output:

Enter how many values to consider: -2 Wrong input. Input must be > 0

Enter how many values to consider: 4 Enter value 1: -3 Enter value 2: -10 Enter value 3: -7 Enter value 4: -3 Maximum value =

Enter how many values to consider: 7 Enter value 1: 4 Enter value 2: 3 Enter value 3: 2 Enter value 4: 1 Enter value 5: 2 Ent

Feel free to open them in new tab if required.

Please read the comments to understand the code. I have tried my best to explain what each and every line does. If you still have any doubt or want me to change something, get back to me in the comment section below. I would love to help you out.

I hope this helps.

----

Your thumbs up means a lot to the expert.

Please leave a thumbs up if you are satisfied with the answer, and if you still have any queries regarding the solution, please feel free to ask in the comments section below. We will get back to you ASAP and would love to help you out. Thanks! Keep Learning, Keep Chegging!! :)

Add a comment
Know the answer?
Add Answer to:
important don't use arrays or listed pleaseeeee in python 3 Write a program that given a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python 3, Write a program that reads a set of floating-point values. Ask the user...

    In Python 3, Write a program that reads a set of floating-point values. Ask the user to enter the values, then print: The number of values entered. The smallest of the values The largest of the values. The average of the values. The range, that is the difference between the smallest and largest values. If no values were entered, the program should display “No values were entered” The program execution should look like (note: the bold values are sample user...

  • In C please! Thank you! Write a program that finds the smallest (min), largest (max), and...

    In C please! Thank you! Write a program that finds the smallest (min), largest (max), and average (mean) of N values entered by the user. Your program should begin by prompting the user for N, the number of values to be entered. Then the program should accept that number of values, determining the min, max, and mean. Then it should display those values. This is an extension of a previous lab. First, get it working for N values. Then, extend...

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • IN C++ Pleaseeeee Write a program to find the sum of the series 1/n+2/n+3/n+4/n+...+n/n, where 1...

    IN C++ Pleaseeeee Write a program to find the sum of the series 1/n+2/n+3/n+4/n+...+n/n, where 1 <= n <= 8 using a function. The user is asked to enter an integer value n. Then the program calls the appropriate function to calculate the sum of the series and then prints the sum to the screen.

  • Write a small JAVA program that continually reads in user values and calculates the average of all values. The program s...

    Write a small JAVA program that continually reads in user values and calculates the average of all values. The program should first ask the user for the number of values to be entered. Upon storing this value, the program should proceed to read in that amount of values. What will be the best strategy here? a suggestion would be only calculating the average after you know you have read in all values. You can expect to use some type of...

  • please code in python 1. Write a program to request the user enter a desired number...

    please code in python 1. Write a program to request the user enter a desired number of values. Create a loop to load the desired number of user-specified values into a list. Create two lists with the same values but generated in different ways. On list will be originally initialized to have the desired length before entering the loop. The other list will begin empty and values be appended for every iteration of the loop. Output from the program should...

  • don't use continuity and break in python 3: (In python3) Exercise # 4: Write a program...

    don't use continuity and break in python 3: (In python3) Exercise # 4: Write a program that prompts for and reads the number ? of spheres to be processed. If ?≤0 your program must display an error message and terminate; otherwise it does the following for ? times: Prompts for and reads the volume of a sphere, it then displays the surface area of the sphere with that volume. Assume that each volume is in cubic centimeters. The program finally...

  • 3. (c-program) Write a program that finds the largest and smallest value in a series of...

    3. (c-program) Write a program that finds the largest and smallest value in a series of numbers entered by a user. The user must enter 25 values. Note if that if the user enters "0" they must correct and add another number. Print out the original entered values, the largest number, the smallest number. Note whether the user tried to enter "O".

  • python program 6 Write an input validation loop that asks the user to enter a number...

    python program 6 Write an input validation loop that asks the user to enter a number in the range of 100 through 1000? 7 Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’? 8 How many times the following loop will repeat? cnt = 0    while  cnt != 5: print(cnt) cnt = cnt + 2

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT