Oct-07-2017, 03:58 PM
Hey guys- I'm on my last assignment for Python and I need some expert assistance please.
This is the assignment:
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.
This is my code:
Invalid input
Maximum is 10
Minimum is 2
This is my output:
7 ← Mismatch
2
bob
Please, enter only numbers.
10
4
Maximum 10
Minimum 2
I need help please.
This is the assignment:
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.
This is my code:
largest = None smallest = None while True: try: num = raw_input("Enter a number: ") if num == "done": break print (num) num = int(num) if largest is None or largest < num: largest = num elif smallest is None or smallest > num: smallest = num except ValueError: print("Please, enter only numbers.") print ("Maximum", largest) print ("Minimum", smallest)This is the Desired output:
Invalid input
Maximum is 10
Minimum is 2
This is my output:
7 ← Mismatch
2
bob
Please, enter only numbers.
10
4
Maximum 10
Minimum 2
I need help please.
