Created
March 16, 2020 21:10
-
-
Save robertlugg/43d4c5be255b3e434927bdb68d6259eb to your computer and use it in GitHub Desktop.
Example User entry and determine min and max values.
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
""" Program to accept list of numbers and return smallest and largest """ | |
def main(): | |
print("Enter numbers. Type 'done' for the number to compute min and max") | |
smallest = largest = None | |
while True: | |
user_entry = input('enter a number ') | |
if user_entry == 'done': | |
break | |
try: | |
number = int(user_entry) | |
except: | |
print('invalid input') | |
continue | |
if smallest is None: | |
smallest = number | |
if largest is None: | |
largest = number | |
smallest = min(number, smallest) | |
largest = max(number, largest) | |
continue | |
if smallest is not None: | |
print(f"Maximum is {largest}") | |
print(f"Minimum is {smallest}") | |
else: | |
print("You must enter at least one number") | |
if __name__ == '__main__': | |
main() |
Author
robertlugg
commented
Mar 16, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment