Python program to read numbers repeatedly find the total, an average of numbers
Develop a program that repeatedly reads numbers until the user enters “done”. Once “done” is entered, print out the maximum and minimum of the numbers. If the user enters anything other than a number, detect their mistake using try and except and print an error message and skip to the next number.
Video Tutorial
Source Code to read numbers display the Maximum and Minimum
max = 0 min = 999 while True: inp = input("Enter the number or done: ") if (inp == 'done'): break else: try: inp = int(inp) if (inp > max): max = inp if(inp < min): min = inp except: print ("Enter the numeric value") continue print ("The maximum number is:", max) print ("The minimum number is:", min)
Output:
Case 1:
Enter the number or done: 10
Enter the number or done: 20
Enter the number or done: hit
Enter the numeric value
Enter the number or done: 15
Enter the number or done: done
The maximum number is: 20
The minimum number is: 10
Case 2:
Enter the number or done: 30
Enter the number or done: 20
Enter the number or done: 10
Enter the number or done: Mahesh
Enter the numeric value
Enter the number or done: 80
Enter the number or done: 50
Enter the number or done: done
The maximum number is: 80
The minimum number is: 10
Summary:
This tutorial discusses how to write a python program to read numbers repeatedly and find the Maximum and Minimum. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.