Trouble getting Python to chose the correct code path

Viewed 56

I was trying to create a guessing game in Python, and it keeps on printing out the else: part even if I typed in the right number (1). What did I do wrong?

print("Pick a number from one to 10 ")
guess = input("Type a number")
num = 1
if guess == 1:
    print("GoodJob actual wizard.")
else:
    print("Try again")
3 Answers

You never specify what type guess is, you need to convert it to an int otherwise comparing it to any integer will be False.

Replace:

guess = input("Type a number")

With:

guess = int(input("Type a number"))

It happens that the input the user will put on your program is actually a string ("1"), which is different from the integer 1. Just switch

guess = input("Type a number")

to

guess = int(input("Type a number"))

Just convert guess variable to an integer and it will perfectly fine for you

guess = input("Type a number")
guess = int(guess)
Related