Skip to content

Instantly share code, notes, and snippets.

  • Save som983/e458c4b7c6be6be7436c3175f83a301b to your computer and use it in GitHub Desktop.
Save som983/e458c4b7c6be6be7436c3175f83a301b to your computer and use it in GitHub Desktop.
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.
largest = None
smallest = None
while True:
try:
num = input("Enter a number: ")
if num == "done":
break
n=int(num)
if n> largest:
largest=n
elif smallest is None:
smallest=n
elif n < smallest:
smallest= n
except:
print("Invalid input")
continue
print("Maximum is", largest)
print("Minimum is", smallest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment