Skip to content

Instantly share code, notes, and snippets.

@AlexJWayne
Last active January 28, 2019 22:53
Show Gist options
  • Save AlexJWayne/92080db347754285aaa039ac57318283 to your computer and use it in GitHub Desktop.
Save AlexJWayne/92080db347754285aaa039ac57318283 to your computer and use it in GitHub Desktop.
# same as Ch5_1b (loops with user input list of numbers generating the count, total and average) but with max and min values instead of count aveage and total
# Setting the running smallest and largest numbers to none so they are defined
smallest_number = None
largest_number = None
# User input loop
while True:
string_number = input('Enter a number.')
# Denoting end of loop with 'done' and printing output of smallest and largest numbers from user list
if string_number == 'done':
print('Smallest number in list:', smallest_number)
print('Largest number in list:', largest_number)
break
# Not yet done. Process the number.
else:
# Catch for non numbers
try:
number = float(string_number)
except:
print('Invalid entry. Enter a number.')
continue
# Smallest number compared to each user input to create running update of current smallest number
if not smallest_number or number < smallest_number:
smallest_number = number
# Largest number compared to current user entry to maintain running update of current largest number
if not largest_number or number > largest_number:
largest_number = number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment