python - 无论输入如何,项目都添加到列表中
问题描述
我们正在为一个班级项目创建一个文本游戏,我对下面定义的语句有疑问。从逻辑上讲,这似乎是正确的,但从功能上讲,它不起作用。无论输入如何,“项目”都会添加到我的列表中。
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
解决方案
推荐阅读
- jenkins - 如何使用 Nuget.exe 获取特定安装的 Nuget 包的版本?
- r - 将嵌套列表的单个元素从因子转换为字符
- java - Java中是否有任何东西可以将系统属性的范围更改为WAR?
- python-3.x - Tensorflow 对象检测 API:在 Cityscapes 数据上推理预训练的 Kitti 模型导致准确性低
- javascript - 单击时执行功能会出错
- r - 有没有更简洁的方法将文本/标签添加到多条垂直线:geom_vline()?
- c# - 对象的全局声明和使用数组 C#
- javascript - 如何从具有多个标签的内部 HTML 中获取 href?
- asp.net-core - 使用从 IdentityUser 继承的自定义用户类时出错
- c# - 多重继承使数据库上的列重复并发生冲突