I am attempting to make a simple text based adventure game in python and have come across a small error where an else command is being called when I do not want it to. The following is a small sample from my code.
## inventory var ##
inv=["torch"]
## inventory function ##
def ichk():
print(f" You are carrying{inv}")
return
##First room, links to a3##
def a2():
move=input("placeholder text.. You notice an exit to your 'east': ")
if move==("e"):
print("You exit to the east")
a3()
if move==("i"):
ichk()
if move==("q"):
print("You find nothing of value")
a2()
else:
print("You can't move in that direction")
a2()
When the function ichk() is triggered (by user input "i"), inventory is printed, howver the else print statement is also printed before returning to the beginning of function a2(). I am new to python so I understand that the constructed argument might not be efficient/effective coding, but I am not sure why this is being triggered.
Thanks to anyone taking the time to read.
Aucun commentaire:
Enregistrer un commentaire