我正在制作一个Python程序,它是一个通过鬼屋的冒险游戏。其中最大的一件事就是名为owned_items
的清单。当他们在房子中找到它们或者在开始时被random.choice
给予它们时,这将获得由诸如“匹配框”或“火炬”之类的字符串表示的项目。有时,当他们面临情况时,他们给出的选择取决于他们是否有特定的项目。Python:在没有运行的if语句中打印
我的代码:
#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')
即使当我知道我的项目3在这些if语句,没有打印的出现。我使用的是ifs而不是elifs和其他,因为我希望它能够显示所有内容,而不仅仅是一个。例如,如果他们有一个玻璃瓶和一把菜刀,我想让它给他们打印瓶子和刀子的声明。
如果这是您的完整代码并忽略'def skeleton_choice()'下的缩进错误,那么您不会调用该函数,因此它不会运行。 – roganjosh
看起来像你的函数有一个不正确的意图,并没有像'def skeleton_choice(input)' – Bryan
这样的输入我不知道这是与问题或我的失败的复制和粘贴,但如果是符合骨骼的sk,而不是def。我看到的缩进没有任何问题。 –