Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble getting Python to chose the correct code path

Tags:

python

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")
like image 811
Can't think of a good one Avatar asked Feb 01 '26 05:02

Can't think of a good one


1 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"))