Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Returning to a previous choice in python

I’m working on a text adventure game for my first big self-made project in Python. I’m trying to figure out how to make it so that the player can go back to a previous area so that they may make another choice. I’m not sure how to do that. Any idea how?

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use while loop here.

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?")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading