2016-11-12 1 views
-2

私は何が間違っているのか分かりません。私は、ユーザーが指定されていない名前を入力した場合、プログラムは、最後にelseステートメントを出力するようにしたいと思います。また、elifのステートメントが機能するようにしたいので、ユーザーが年齢を入力すると、正しいprintステートメントが表示されます。どのように私はこの作業を行うので、名前が指定されていない場合、それは他のものに行き、なぜelnt文が動作しないのですか

name = input("What is your name?") 
if name == "Jean Gray" or "Max Eisanhardt" or "James Howlett" or "Anne Marie": 
    age = int(input("How old are you?") 
    if age <= 12: 
    print ('You should be placed in the junior category because you are younger than 12 years old') 
    elif age >= 18: 
    print ('You should be placed in the senior category because you are older than 18 years old') 
    elif age <=17: 
    print ('You should be places in the teen category')   
else: 
    print("Sorry, that name is not recognised.") 
+0

'名==「ジーン・グレイ」または「マックスEisanhardt」や「ジェームズ・ハウレット」の場合または「アンMarie "':この行はあなたが思っていることをしていません。 'name'が各文字列と等しいかどうかテストします。 'name'が' 'Jean Gray''と等しい場合の唯一のテストです。 ifステートメントの他の文字列は、 "真実性"についてのみテストされます。 –

答えて

-1

あなたの文は、常に現在trueに評価される場合は、次の構文を使用する必要があります

if a == "value1" or a == "value 2" or a == "value3": 
    //do something 
関連する問題