为什么if语句在it代码块落入else代码块后还在执行?

Why is the IF statement still executing after it code block falls into the ELSE code block?

Click here for Image of my Code

我正在编写一个简单的基于文本的冒险游戏,因为我仍在学习 python 的基础知识。 控制台在第 15 行返回错误。else 条件在第 14 行执行,但看起来程序仍在尝试执行,代码在第 14 行之后。据我了解,在执行 else 语句后没有 if 语句在代码块内将被执行?

print("Welcome to Treasure Island.\nYour mission is to find the treasure")

step_1 = input("Would you like to go left or right?")

if step_1.lower() == "left":
    step_2 = input("Swim or wait?")  
    if step_2.lower() == "wait":
       step_3 = input("Which door Red, Yellow or Blue?")
    else:
        print("Attacked by a trout. GAME OVER!") 
    if step_3.lower() == "red":
        print("Burned by fire. Game Over.")
    elif step_3.lower() == "blue":
        print("Eaten by beasts. Game Over.")
    elif step_3.lower() == "yellow":
        print("You Win!")
    else:
        print("Game Over.")     
else:
    print("You have fell into a hole, Game Over!")

根据您的代码,step_3 仅在第 11 行的 if 块中可用。要解决此问题,您需要在 if 块上方声明 step_3,然后为其赋值在第 11 行的 if 块中