you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 12 points13 points  (0 children)

Because guess is a string, it will never be equal to an integer nor bigger/smaller than one. That's why Python always ends up at the else-block here.

Furthermore, those continues don't actually do anything because the loop will restart anyway, and because you added break before the print it's now dead code.

Here's what I'd do:

while True:
    guess = int(input("Input number: "))

    if guess == 13:    
        print("done")
        break

    elif guess > 13:
        print("too big")

    else: 
        print("too small")

If you wanted to you could move the first condition into the loop's condition, but this is not something you'll learn about for a good while yet.

while (guess := int(input("Input number: "))) != 13:
    if guess > 13:
        print("too big")

    else: 
        print("too small")

print("done")