2016-06-12 16 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」と表示され続けます。なぜですか?どうしましたか?この単純なコードはなぜ間違っていますか?

+0

ウッシングのpython 3私はTypeError例外 '得る:unorderableタイプ:STR()> = INT()'と私は何の問題を取得していないのpython 2を使用して。 (それ以外の文字列名は使用できません) –

+0

@ Tadhg、エラーは発生しませんが、間違った答えが出ます。 Python 2は、互換性のない型の_names_を比較します。 ( '" int "<" str "') – alexis

+0

@alexisいいえ、Python 2 Python 3に 'K'を出力する時に' 15'をタイプすると、strとの比較時にエラーが発生します。 int、私は15を入力したとき最後に私に "Sorry bruh"を表示する '' 'を再現することができません。' '' –

答えて

3

キャストは、あなたのinputintに:

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

あなたはtry-exceptを追加することができます。 name=raw_input("What is your name?")

+0

それはとても愚かでした。ありがとうございました – Metalnakls

0

orに評価されるべき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") 
0

[OK]をので、あなた:あなたの条件が均等にあなたがのpython3を使用していて、int(input("Your age"))にキャストする必要があるか、Python2を使用して、あなたが名前を読み取るためにraw_inputを使用する必要はないかand

関連する問題