2016-08-25 4 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 imagea Заявление внутри оператора if?

+0

жаль, что не в питона языка я аутизм и я плохо stackflow, если кто-нибудь может научить меня, как поставить его на языке программирования также будет hlep: ^) – 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

Вы можете отступ дополнительных заявлений, в том числе if операторов внутри существующего if блока, так же, как вы отступом первого print заявления. Это не ясно из вашего вопроса, что именно вы хотите сделать, так что я буду заполнять какой-то псевдо-код (который вы можете заменить с тем, что вы на самом деле хотите):

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." 
Смежные вопросы