Skip to content

Instantly share code, notes, and snippets.

@hareom284
Created July 17, 2020 05:29
Show Gist options
  • Save hareom284/c0cdef3a8e070641494937143f2f3d0c to your computer and use it in GitHub Desktop.
Save hareom284/c0cdef3a8e070641494937143f2f3d0c 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. Enter 7, 2, bob, 10, and 4 and match…
largest = None
smallest = None
while True:
num = input("Enter a number: ")
if num == 'done':
break
try :
num = int(num)
if (largest==None) :
largest = num
if (smallest==None) :
smallest =num
if largest < num :
largest = num
if smallest >num :
smallest = num
except :
print("Invalid input")
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