Skip to content

Instantly share code, notes, and snippets.

@robertlugg
Created March 16, 2020 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertlugg/43d4c5be255b3e434927bdb68d6259eb to your computer and use it in GitHub Desktop.
Save robertlugg/43d4c5be255b3e434927bdb68d6259eb to your computer and use it in GitHub Desktop.
Example User entry and determine min and max values.
""" 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()
@robertlugg
Copy link
Author

min_max_py

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