Answer to Question #302422 in Python for reyadhhf

Question #302422

Write a Python program that asks the user for a quantity, then takes that many numbers as input and prints the maximum, minimum and average of those numbers.


[Please note that you CANNOT use max, min built-in functions]


[Also, you DO NOT need to use lists for this task]


==========================================================


Example: If the user enters 5 as an input for quantity and the enters the 5 numbers, 10, 4, -1, -100, and 1.

The output of your program should be: “Maximum 10”, “Minimum -100”, “Average is -17.2” as shown below.


Input:

5

10

4

-1

-100

1


Output:

Maximum 10

Minimum -100

Average is -17.2


1
Expert's answer
2022-02-26T05:51:57-0500
n = int(input())
sum, min, max = 0, 0, inf
for i in range(n):
  x = int(input())
  sum = sum + x
  min = (min < x ? min : x)
  max = (max > x ? max : x)
print('Maximum', max)
print('Minimum', min)
print('Avarage is', sum / n)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS