首页 > 解决方案 > 无论输入如何,项目都添加到列表中

问题描述

我们正在为一个班级项目创建一个文本游戏,我对下面定义的语句有疑问。从逻辑上讲,这似乎是正确的,但从功能上讲,它不起作用。无论输入如何,“项目”都会添加到我的列表中。

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

这是我收到的以下输出:

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 

标签: python

解决方案


推荐阅读