我正在制作一个蟒蛇程序,这是一个冒险游戏的东西,通过鬼屋。其中最重要的事情之一是一个名为owned_items的列表。这会得到一些字符串表示的项目,比如,“火柴盒”或“火炬”,当他们在房子里找到它们时,或者在开始时由random.choice提供给它们。有时,当他们遇到某种情况时,他们得到的选择取决于他们是否有特定的物品。
我的代码:
#bullets is the variable for pistol ammo. During my testing of this function, it is at 5 when it should start
bullets=5
owned_items=[]
ronald_items=["a glass bottle", "a pistol", "a torch", "a small glass of oil", "a box of matches", "a can of spray paint", "a small knife", "a pair of surgical gloves", "a blessed amulet"]
owned_items.append(random.choice(ronald_items))
ronald_items.remove(owned_items[0]
owned_items.append(random.choice(ronald_items))
ronald_items.remove(owned_items[1])
#This part is in the actual definition where the problem appears when it should run
def skeleton_choice():
if "a glass bottle" in owned_items:
print('type "glass bottle" to attack the skeletons with that bottle')
if "a pistol" in owned_items and bullets>1:
print('type "shoot" to try firing your pistol at the skeletons')
if "a small knife" in owned_items:
print('type "small knife" to use your small knife against the skeletons')
if "a kitchen knife" in owned_items:
print('Type "kitchen knife" to use your kitchen knife against the skeletons')
if "a blessed amulet" in owned_items:
print('Type "amulet" to use the blessed amulet to make this a fairer fight')
print('Type "hands" to just fight the skeletons with your body')
print('Type "run" to try and get away from the skeletons')即使我知道我在这些if语句中有3项,但没有打印出来。我使用的是ifs,而不是elifs和一个其他的,因为我希望它能显示他们拥有的一切,而不仅仅是一个。例如,如果他们有一个玻璃瓶和一个菜刀,我希望它给他们打印声明的瓶子和刀。
发布于 2016-12-03 12:09:37
您还没有在任何地方调用该函数,这就是它不能工作的原因。只需添加:
skeleton_choice()最后排好队。也在排队
ronald_items.remove(owned_items[0]你少了一个括号。
发布于 2016-12-03 12:09:25
你的密码对我有用。在我将调用添加到skeleton_choice()之后。可能是你不这么说吗?
https://stackoverflow.com/questions/40947165
复制相似问题