2016-06-12 103 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") 
相關問題