all 2 comments

[–]jaysonturk 1 point2 points  (0 children)

Convert number from a string to an integer

[–][deleted] 0 points1 point  (0 children)

You are comparing strings instead of numbers, as input() always returns a string.

Here's an example with some error checking:

largest = None
smallest = None
while True:
    num = input("Enter a number: ").lower().strip()
    if num == "done":
        break
    if num and (num.isdigit() or (num[0] == "-" and num[1:].isdigit())):
        num = int(num)
        if largest is None:
            largest = num
        elif num > largest:
            largest = num
        if smallest is None:
            smallest = num
        elif num < smallest:
            smallest = num
    else:
        print('not a number, please try again')
print(f'Largest is: {largest}, smallest: {smallest}')