I am making a text game in Python. I need this to ONLY print "You cannot go that way, try a different direction" when the direction is not a valid move. But this is printing every time.
#show_game_instructions()
while True:
print('What direction do you want to go?')
direction = input()
current_room = rooms[current_room][direction]
print('You are in ' current_room)
if 'item' in rooms[current_room]:
print('The item in this room is the', rooms[current_room]['item'])
print('To add to to inventory: type "get" and the name of the item in this room')
if direction not in rooms[current_room]:
if direction != 'North''South''East''West':
print("You cannot go that way, try a different direction')
CodePudding user response:
I suspect this line is not doing what you think it should do
direction != 'North''South''East''West'
if you want to check that direction is not one of those options you could do
if direction.lower() not in ['north', 'south', 'east', 'west']:
print("You cannot go that way, try a different direction')
CodePudding user response:
Try replacing the IF statement with this:
if direction not in ['North', 'South', 'East', 'West']: