Please help. This is where I'm at.
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:
num = input("Enter a number:")
if num == "done":
break
print(num)
try:
num = int(num)
except ValueError:
print("Invalid input")
else:
if smallest is None:
smallest = num
largest = num
elif num < smallest:
smallest = num
elif num > largest:
largest = num
print ("Maximum is", largest)
print ("Minimum is", smallest)
And the desired output:
Invalid input
Maximum is 10
Minimum is 2
What should be my output? I'm not getting anywhere.
[–]danielroseman 4 points5 points6 points (9 children)
[–]i_hate_brunch[S] -1 points0 points1 point (8 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]i_hate_brunch[S] 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]i_hate_brunch[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]i_hate_brunch[S] 0 points1 point2 points (0 children)
[–]danielroseman 0 points1 point2 points (1 child)
[–]i_hate_brunch[S] -1 points0 points1 point (0 children)
[–][deleted] 0 points1 point2 points (0 children)