Skip to content

Instantly share code, notes, and snippets.

@KKarthikeya
Created August 16, 2015 04:21
Show Gist options
  • Save KKarthikeya/eb760bd6462add9ce1e1 to your computer and use it in GitHub Desktop.
Save KKarthikeya/eb760bd6462add9ce1e1 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:
num = raw_input("Enter a number:")
try:
if num == 'done':
print "Maximum is",largest
print "Minimum is",smallest
break
num = int(num)
if largest is None:
largest = num
if smallest is None:
smallest = num
if largest < num :
largest = num
if smallest > num :
smallest = num
except:
print "Invalid input"
@Istifanusakaka
Copy link

that's very good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment