0

我对此有疑问,我无法让 2 个单独的 if 语句相互匹配。例如,我想将 A1==2" 与 A4=="1" 匹配。请帮助!!!(忽略 TROLO,只是临时结束。)

print ("You find yourself in a dark room, do you... (1) Try to find a way out... or... (2) Sit down and think.")
A1 = input('>>')
if A1 == '1':
        print ("You go into panic, you begin to feel dizzy and lightheaded...")
        print ("Do you (1) Sit down and try to relax... or... (2) Slow down, but keep searching.")
elif A1 == '2':
        A2 = input('>>')
    print ("You sit down and catch your breath for a minute.")
    print ("Do you (1) Get back up and keep feeling your way around ... or ... (2) Lay down for a mintute or two longer.")
A1 = input('>>')
if A1 == '2':
        print ("You sit down and catch your breath for a minute.")
        print ("Do you (1) Get back up and keep feeling your way around ... or ... (2) Lay down for a mintute or two longer.")

input ("TROLOLOLO") 
4

2 回答 2

1

我想你想要的是这样的:

print("You find yourself in a dark room, do you... (1) Try to find a way out... or... (2) Sit down and think.")
A1 = input('>>')
if A1 == '1':
    print ("You go into panic, you begin to feel dizzy and lightheaded...")
    print ("Do you (1) Sit down and try to relax... or... (2) Slow down, but keep      searching.")
elif A2 == '2':
    A4 = input('>>')
    etc

elif表示else if。它是同一个条件的一部分,所以如果 A1 等于“1”,它就会这样做。否则,如果 A2 == '2',则要求A4

于 2013-11-07T03:16:32.017 回答
0

首先修复这些缩进并将 if 条件更改为 elif。此外,如果您没有进入 if 块,请考虑删除这些引号:

if A1 == 1:
于 2013-11-07T03:18:27.557 回答