This is my code for a if/elif/else conditional for a text-based adventure game I'm working on in Python. The goal of this section is to give the player options on what to do, but it says there is something wrong with the syntax of all of my "elif" statements.
if command.lower() in ["north", "n"]:
#With invitation
if "invitation" in items:
castle()
#Without 'Invitation'
else:
print "As you walk towards the gate, a guard approaches you and pushes you away. "Sorry, pal," says the guard,"You can't get in the castle without a written invitation from the king""
town_center()
elif command.lower() in ["east", "e"]:
#market()
elif command.lower() in ["south", "s"]:
#forest()
elif command.lower() in ["west", "w"]:
#village()
elif command.lower() in ["inventory", "i"]:
print items
town_center()
elif command.lower() in ["look", "l"]:
print "
You are standing in the center of the rural town of Grifiinhorn, a quaint rural town in the province of Bedrin. To the north, you see a giant castle sitting on top of a hill. To the east is the marketplace, and to the west is the village. To the south is exit gates of the town which faces the Dark Forest.
"
town_center()
else:
town_center()
I always get this error:
elif command.lower() in ["east", "e"]:
^
SyntaxError: invalid syntax
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…