Just trying to figure out why my code here is returning the incorrect minimum and maximum values. tried flipping the ">" and "<" around and it still doesn't work. I'm not meant to use the min() and max() functions here. My thought was maybe I should hold all of the input values in another variable and then check that one for the min and max values?
largest = None
smallest = None
while True:
num = input("Enter a number: ")
if num == "done":
break
try:
int(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)
print("Maximum is", largest, "Minimum is", smallest)Output:Enter a number: 9
Enter a number: 41
Enter a number: 12
Enter a number: 3
Enter a number: 74
Enter a number: 15
Enter a number: done
Maximum is 12 Minimum is 9
