2016-06-12 60 views
-4
print("Hello there") 
name=input("What is your name?") 
print("Welcome to the some game, " + name + "!") 
print("I'm going to ask you some basic questions so that we could work together") 
age=input("Your age") 
if age >= 14 and age < 41: 
    print("K") 
else: 
    print("Sorry bruh") 
print("Thanks") 

不断向我展示“Sorry bruh”,当输入15时结束。为什么?怎么了?为什么这个简单的代码是错误的?

+0

尤斯巨蟒-3我得到'类型错误:unorderable类型:STR()> = INT()'和使用Python 2我没有得到任何问题。 (其他然后不能使用字符串名称) –

+0

@Tadhg,你得到没有错误,但你得到了错误的答案。 Python 2在不兼容的情况下比较类型的_names_! ('“int”<“str”') – alexis

+0

@alexis no,对于python 2,如果您在输入'15'时输入'K',则在python 3上尝试比较str时发生错误int,所以我无法重现'''显示我“抱歉bruh”在进入15时结束。''' –

回答

3

投你inputint

age = int(input("Your age")) 

你可以添加一个try-except。你的情况应同样对orand

+0

那太蠢了。谢谢 – Metalnakls

0

无论您使用Python3评估,并需要用int(input("Your age"))投或使用Python2,然后你需要使用raw_input读取名称:name=raw_input("What is your name?")

0

好了,你可以尝试在python2.7这个代码和按你们的要求,将工作:

print("Hello there") 
name=raw_input("What is your name?") 
print("Welcome to the some game, " + name + "!") 
print("I'm going to ask you some basic questions so that we could work together") 
age=input("Your age") 
if age >= 14 and age < 41: 
    print("K") 
else: 
    print("Sorry bruh") 
print("Thanks") 
相关问题