Created
August 21, 2017 14:30
-
-
Save AmruthPillai/77026640f8be299fd3d61e740034c1fa 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 = raw_input("Enter a number: ") | |
if num == 'done': | |
break; | |
n = int(num) | |
largest = num if largest < num or largest == None else largest | |
smallest = num if smallest > num or smallest == None else smallest | |
except: | |
print "Invalid input" | |
print "Maximum number is ", largest | |
print "Minimum number is ", smallest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num == "done" : break
try:
num = int(num)
except:
print("Invalid input")
continue
print("Maximum is", largest)
print("Minimum is", smallest)