Aug-30-2020, 05:10 AM
(This post was last modified: Aug-30-2020, 05:11 AM by SteppentigerV2.)
I'm stuck with this. This is the requirement 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.
My code:
My code:
largest = None smallest = None while True: num = float(input("Enter a number: ")) for i in num: if i > largest: largest = i print(largest) break for i in num: if num <smallest smallest=num print(num) except print("Invalid input) if num == "done" : break print(num) print("Maximum is", largest, "Minimum is", smallest)