If 语句 python

If Statements on python

这有什么问题吗?

passcode = 10

question = raw_input("type code ")

if question == passcode:
    print"yey"

使用此代码解决您的问题......

passcode = 10

question = raw_input("type code ")

if passcode == int(question):
    print"yey"

您正在尝试将字符串 "10" 与整数 10 进行比较。这些不是一回事。您需要使用 int() 将字符串输入转换为 int。但是,您需要注意用户只能输入整数。

passcode = 10

question = raw_input("type code ")

if int(question) == passcode:
    print "yey"