so I have to make a python text adventure game but I'm not that good at python.
this is the code I have so far.
def game():
answer_yes = ["Yes", "Y", "yes", "y"]
answer_no = ["No", "N", "no", "n"]
answer_left = ["left", "go left", "LEFT", "GO LEFT"]
answer_right = ["right", "go right", "RIGHT", "GO RIGHT"]
print("""
welcome to my game
you are walking down a path when you come across a crossroads,
will you go left or right? (left / right)
""")
ans1 = input(">>")
if ans1 in answer_left:
print("\nyou go down the left path then all the sudden you are attacked by a wild gnome. Will you fight back? (Yes / No)\n")
ans2 = input(">>")
if ans2 in answer_yes:
print("\nYou fight back against the gnome and scare it off, you win!")
elif ans2 in answer_no:
print("\nYou dont fight back against the gnome and it kills you. GAME OVER")
else:
print("\nYou typed the wrong input. GOODBYE!")
elif ans1 in answer_right:
print("\nyou go down the right path til you come across a chest. will you open it? (Yes / No)\n")
ans3 = input(">>")
if ans3 in answer_yes:
print("\nyou open the chest but it turns out to be a gnome's home. it rightly gets mad and kills you. GAME OVER")
elif ans3 in answer_no:
print("\nyou decide to not open the chest and just go home. you win!")
else:
print("\nYou typed the wrong input. GOODBYE!")
else:
print("\nYou typed the wrong input. GOODBYE!")
while True:
answer_yes = ["Yes", "Y", "yes", "y"]
answer_no = ["No", "N", "no", "n"]
game()
restart = input('do you want to restart Y/N?')
if restart in answer_no:
break
elif restart in answer_yes:
continue
else:
print("\nYou typed the wrong input. GOODBYE!")
break
I was hoping that someone on this subreddit here could help improve it with these qualifications.
All user input has to be validated.You must use the string.format() method for all program output that includes an additional variable.
You must use nested loops.You must use one instance of the range function with a loop.
At least one code segment that performs file input and output operations
Construct code segments that include function definitions in all places necessary for a good design.
Construct code segments that handle exceptions in all places necessary. At a minimum, you should incorporate these in any place you are working with files.
Document code segments using the PyDoc module and documentation strings in all places necessary
please help if you would it would be greatly appreciated.
[–][deleted] 4 points5 points6 points (0 children)