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 :
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?")