返回到 python 中的先前选择

Returning to a previous choice in python

我正在为我在 Python 的第一个大型自制项目开发文字冒险游戏。我想弄清楚如何做到这一点,以便玩家可以回到之前的区域,以便他们做出另一个选择。我不知道该怎么做。知道怎么做吗?

answer_yes = ["Yes" ,"Y" ,"yes" ,"y" ]
answer_no = ["No" ,"N", "no", "n"]
answer_north = ["North", "N"]
answer_south = ["South", "S"]
answer_east = ["East", "E"]
answer_west = ["West" "W"]



print("""
Welcome to Ziggy's Adventure

You are standing in a field, north of the coast, to your north is a beach, to your west is a dirt path, which way will you go?
""")

ans1 = input(">>")

if ans1 in answer_north:
    print(
        "\n You arrive at the beach, the sound of seagulls and the salty sea air, you can see the beach, "
        "there is nothing much here. Where will you go now?")
    ans1

这里使用 while 循环。

answer_yes = ["Yes" ,"Y" ,"yes" ,"y" ]
answer_no = ["No" ,"N", "no", "n"]
answer_north = ["North", "N"]
answer_south = ["South", "S"]
answer_east = ["East", "E"]
answer_west = ["West" "W"]


while True:
  print("""
  Welcome to Ziggy's Adventure

  You are standing in a field, north of the coast, to your north is a beach, to your west is a dirt path, which way will you go?
  """)

  ans1 = input(">>")
  if ans1.lower() == 'exit':  # add an if statement if input is exit then exit(break) the loop.
    break

  if ans1 in answer_north:
      print(
          "\n You arrive at the beach, the sound of seagulls and the salty sea air, you can see the beach, "
          "there is nothing much here. Where will you go now?")