在Python文本冒险游戏中检查特定项目的清单并返回true。

2024-04-29 07:58:14 发布

您现在位置:Python中文网/ 问答频道 /正文

当我键入任何当前保存的要使用的项时,无法激发以下代码。在这之前我做了一个库存检查,并且已经有了。你知道吗

"You are holding:  ['GOLD', 'SWORD', 'STONE MARBLE']"

放在那里

inventory = []
inventory.append("GOLD")
inventory.append("SWORD")
inventory.append("STONE MARBLE")

但是当我在下面的输入中输入STONE MARBLE时,它会触发else语句。你知道吗

def statue_item_room():

print("Which item do you wish to use?")
item = input("> ")

if item.upper() == ("STONE MARBLE" and item.upper in inventory):
    print(f"You attempt to fit the {item} into the eye socket")
    input("< ")
    print("There is a slight rumble as the statues eye clicks into place, the portcullis slams shut over the left exit and another hidden one slams down from your entrance. Now all exits are sealed and you will eventually starve to death in the chamber, unless something more horrible happens....")
    dead("YOU STARVED")

elif item.upper() == ("GLASS MARBLE" and item.upper in inventory):
    print(f"You attempt to fit the {item} into the eye socket")
    input("< ")
    print("There is a slight rumble as the statues eye clicks into place, the portcullis rises up as the eye shines bright. WIthout hesitation you step forward through the archway")
    door_room()

else:
    print(f"You do not have {item}, pick AGAIN or type LEFT to leave by the open exit")
    choice = input("> ")
    if choice.upper() == "AGAIN":
        statue_item_room()
    elif choice.upper() == "LEFT":
        skeleton_room()

谢谢你的帮助。你知道吗


Tags: andthetoyouinputitemupperroom