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.
Answers
Answered by
0
Answer:
# python3.6.9
# ans will be the iteration variable
ans = None
# li is an empty list
li = []
# it will continue taking inputs until the used enters 'done'
while ans != 'done' :
try:
user_inp = input("Enter interger value - ")
li.append(int(user_inp))
ans = input("Enter 'done' to stop else press enter button ")
except:
# the invalid value gets ignored with a message to user
print("Invalid Input!")
print("Max value = ", max(li)) # max() function
print("Min value = ", min(li)) # min() function
Similar questions