i am attempting to use this loop to determine the max and min values inputted by a user. the provided numbers that are to be inputted are as follows: 7 2 10 4
largest = None
smallest = None
while True :
num = input('Enter a number: ')
if num == 'done' :
break
try :
float(num)
except :
print('Invalid input')
continue
if largest is None :
largest = num
elif num > largest:
largest = num
if smallest is None :
smallest = num
elif num < smallest :
smallest = num
print(num, largest, smallest)
print('Maximum is', largest)
print('Minimum is', smallest)
for the first two numbers the code seems to run smoothly, i have the "print(num, largest, smallest)" statement at the bottom of the loop that verifies this.
however when i input "10" it counts it as the minimum value and not the maximum.
i understand that python inputs as strings and one must convert said inputs to integers or floats, however i am sort of lost as to how this seems to work with single digit numbers but once i use 2 digits numbers, they do not read through as maximum values.
hopefully this is a simple problem to fix, any help is greatly appreciated.