【发布时间】:2017-03-01 03:36:13
【问题描述】:
好的,所以我应该创建一个向导清单程序,列出向导当前拥有的物品。他最多可以拿 4 件物品,从 3 件开始。我的功能似乎是问题所在,但我不确定我在书中做错了什么。
我的显示功能就像一个魅力......我的编辑不是编辑......是的。我只是把这个贴出来,希望你们能告诉我我做错了什么。感谢您提前提供的所有帮助。 (不,我没有要求任何人做我的作业......但也许只是指出我正确的方向)
print ("The Wizard Inventory program")
inventory = ["orb", "staff", "spellbook"]
def opening_menu():
print("Command Menu")
print("show - Show all items")
print("grab - Grab an item")
print("edit - Edit an item")
print("drop - Drop an item")
print("exit - Exit program")
print()
def show_it():
inventory = ["orb", "staff", "spellbook"]
for item in inventory:
print(item)
def grab_it():
print("which item would you like to add??" )
if (item -1) in range (master_inventory_list):
while yes:
grab_it (inventory, " ")
def edit_it():
inventory = ["orb", "staff", "spellbook", "hat", "potion", "robe"]
item = input("What item are you looking for? ")
if item in inventory:
inventory.remove(item)
def drop_it():
inventory = ["orb", "staff", "spellbook", "hat", "potion", "robe"]
item = input("What item would you like to drop? ")
for item in inventory:
inventory.pop()
def exit_it():
choice = y
while choice.lower() == "y":
print("Do you want to stay inside your inventory? (y/n): ")
print()
print("Goodbye!!")
def master_inventory_list():
master_inventory_list = ["orb", "staff", "spellbook", "hat", "potion", "robe"]
opening_menu()
while True:
command = input("Command: ")
if command.lower() == "show":
show_it()
elif command.lower() == "grab":
grab_it()
elif command.lower() == "edit":
edit_it()
elif command.lower() == "drop":
drop_it()
elif command.lower() == "exit":
break
else:
print("Not a valid choice! Please choose again. \n")
print("Goodbye!")
if __name__ == "__main__":
main()
【问题讨论】:
标签: list function python-3.x