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
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)
Comments
Leave a comment