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...

  • 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...

  • C++ please no arrays! Create a program that will allow the user to enter up to...

    C++ please no arrays! Create a program that will allow the user to enter up to 50 whole values and determine the number of values entered, how many of the values were odd and how many of the values were even. Your code should contain 2 functions, a main function and a function to enter the numbers enter and count the values. Your main function should be a driver program that will call another function to count the total number...

  • 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 python please.. Problem 4 (Tracking Statistics – Part 1) Write a program that repeatedly asks...

    In python please.. Problem 4 (Tracking Statistics – Part 1) Write a program that repeatedly asks the user to enter an integer until they want to quit (e.g., by entering ‘q’). The program should then print the largest number entered, the smallest number entered, the average of all numbers entered, the number of positive numbers entered, and the number of negative numbers entered (0 should not count as positive or negative). Problem 5 (Tracking Statistics – Part 2) Copy your...

  • 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...

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • 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".

  • 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.

  • Do pseudocode in java Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that...

    Do pseudocode in java Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and number of times it appeared as shown...

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