2016-08-25 23 views
-4
FarmGround=input("Do you want to pat the animal? ") #this is the input 
if FarmGround==("Yes") or FarmGround==("yes"): #this is if 
    print("You patted the animal") #print statement if you patted the animal it will go onto the next if statement 
if print=("You patted the animal"): 
elif FarmGround==("No") or FarmGround==("no"): #this is elif 
    print("You didn't patt the animal and it is triggered") 

undescribed imageifステートメント内のifステートメント?

+0

それはPython言語で私は自閉症を持っていないし、誰がどのようにもHLEPうプログラミング言語でそれを置くために私を教えることができる場合、私はstackflowで悪い思います申し訳ありません: – mememan

+0

)^あなたは疑問を持っていましたか? –

+0

if文の中にif文を入れたいと思います。 – mememan

答えて

2

コードはかなり明確です。私が理解していることは、動物が暴行されたかどうか別の質問をしたいということです。

FarmGround=input("Do you want to pat the animal? ") #this is the input 

if FarmGround=="Yes" or FarmGround=="yes": #this is if 
    print("You patted the animal") 

    holy_field = input("Did you clear the field?") 
    if holy_field.lower() == "yes": 
     print("Do something else. Don't look at me.") 
    else: 
     print("When are you going to do it ?")   
elif FarmGround== "No" or FarmGround== "no": #this is elif 
    print("You didn't patt the animal and it is triggered") 
+0

私はこれが欲しいですが、私は入力をしたくありません – mememan

2

あなたが最初print文をインデントしているだけのように、既存のifブロック内ifステートメントを含む、追加のステートメントをインデントすることができます。それは正確にあなたが何をしたいのか、あなたの質問から明らかではないので、私は(あなたが実際に好きに置き換えることができます)いくつかの擬似コードを記入します:Pythonで

FarmGround=input("Do you want to pat the animal? ") 
if FarmGround==("Yes") or FarmGround==("yes"): 
    print("You patted the animal") 
    some_other_answer = input("Some other question?") # here's more code inside the first if 
    if some_other_answer == "Foo": # it can include another if statement, if you want it to 
     print("Foo!") 
elif FarmGround==("No") or FarmGround==("no"): 
    print("You didn't patt the animal and it is triggered") 
1

インデントの問題。別のifステートメントでifステートメントをネストするには、最初のステートメントを4つのスペースでインデントします。

If (var1 == 1): 
    If (var2 == 2): 
     print "Both statements are true." 
関連する問題