0

We are creating a text game for a class project and I have an issue with the defined statement below. Logically, it seems right, but functionally, it is not working. The 'Item' is added to my list regardless of the input.

def show_item(current_location):
    room_item = ''
    if 'Item' in current_location:
        room_item = current_location['Item']
        print('You see a', room_item)
        pick_up = input('Would you like to pick up item?')
        if pick_up == 'Yes' or 'yes' and room_item not in current_items:
            current_items.append(room_item)
        elif pick_up != 'Yes' or 'yes':
            pass
        else:
            print('You currently have this item')
    else:
        print('Invalid Input')
    return room_item

This is the output below I receive:

Escape The Freeze
Collect 6 items to win the game, or be frozen alive!
Move commands: South, North, East, West or Exit 

Invalid Input
You are in the Gym
Your current items: 
Enter a command North
You see a meal
Would you like to pick up item?No
You are in the Teachers Lounge
Your current items: meal
Enter a command South
Invalid Input
You are in the Gym
Your current items: meal
Enter a command South
You see a gloves
Would you like to pick up item?woo woo
You are in the Office
Your current items: meal,gloves
Enter a command 
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • `if pick_up == 'Yes' or 'yes'` and `elif pick_up != 'Yes' or 'yes'` make sense in English but computers require such tests to be written a bit differently. See the [linked question](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-single-value) for explanations of why and what to write instead. – John Kugelman Jun 19 '21 at 23:37
  • Made some changes and it is working closer to the intended design. – eyeTcoder24 Jun 20 '21 at 00:43

0 Answers0