【发布时间】:2015-05-26 10:55:35
【问题描述】:
您好,我是 Python 新手,正在学习列表。
我正在编写一个小益智文字游戏,需要您使用基本命令从一个房间移动到另一个房间(功能到功能)。有些房间有陷阱,他们需要一个物品来移除陷阱。 E.G 房间里的熊要求你先找到蜂蜜,然后把它交给熊。我也了解如何 .remove() 和 .append() 列表。
我创建了 2 个列表:
inventory = ["Honey"]
trap = ["Bear"]
当我和熊一起进入房间并且我有蜂蜜时,我可以通过,但是我如何制作一个循环或#Something#来检查“陷阱”列表,以便如果“熊”元素不是t 在列表中,他们不需要蜂蜜通过,因为很明显,一旦他们在熊身上使用它,我就会从“库存”列表中删除“蜂蜜”。理论上,如果他们离开房间并想重新进入,他们就不再需要蜂蜜了。
我想我对这个的理解是这样的,也假设你已经找到了蜂蜜:
def room1()
print "You are in ROOM 1"
if #item is not in list# and #bear is not in the room#:
room2()
elif #item is in the bag#:
print "You give the honey to the bear, and it is distracted"
inventory.remove("Honey")
trap.remove("Bear")
room2()
else:
print "You die to the bear"
exit()
我真的很感激任何建议,甚至是解决这个问题的不同方法。 非常感谢!
【问题讨论】:
-
if 'Bear' in trap and 'Honey' in inventory:?
标签: python list python-2.7 loops evaluate