Python Forum

Full Version: [split] Python for Everybody 5.2 assignment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
largest = None
smallest = None
while True:
    num = input("Enter a number: ")
    if num == "done":
        break
    try:
        fnum = float(num)
    except:
        print("Invalid input")
        continue
    if largest is None :
    	largest = float(num)
    elif num > largest :
        largest = float(num)
    if smallest is None :
        smallest = float(num)
    elif num < smallest :
    	smallest = float(num)
    print(num)
    print("Min:",smallest)
    print("Max:",largest)
print("Maximum is",int(largest))
print("Minimum is",int(smallest))
Can someone help point to where I have gone wrong with the logic please? Thanks!
Can you be more specific? What inputs are you using? How exactly is the behavior different from what you want?
(Jun-14-2019, 04:38 PM)jonchanzw Wrote: [ -> ]elif num > largest :

num is a string. largest is a float. You have an fnum variable available, why not use that for comparisons?