Forked from jennyonjourney/5.2 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,
Last active
February 21, 2022 02:59
-
-
Save initiatorvaibhav/3758f116f237ef60e9c5ca4e8b18f788 to your computer and use it in GitHub Desktop.
[Coursera] Python for everybody 5.2 Assignment
This file contains hidden or 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
largest = None | |
smallest = None | |
while True: | |
inp = input("Enter a number: ") | |
if inp == "done": break | |
try: | |
num = float(inp) | |
except: | |
print("Invalid input") | |
continue | |
if smallest is None: | |
smallest = num | |
largest = num | |
if num < smallest: | |
smallest = num | |
elif num > largest: | |
largest = num | |
print("Maximum is", int(largest)) | |
print("Minimum is", int(smallest)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
newer update