我正在尝试制作一个用于 RPG 的库存程序。该程序需要能够添加和删除事物,然后将它们添加到列表中。这是我到目前为止所拥有的:
inventory=["sword","potion","armour","bow"]
print(inventory)
print("\ncommands: use (remove) and pickup (add)")
selection=input("choose a command [use/pickup]")
if selection=="use":
print(inventory)
remove=input("What do you want to use? ")
inventory.remove(remove)
print(inventory)
elif selection=="pickup":
print(inventory)
add=input("What do you want to pickup? ")
newinv=inventory+str(add)
print(newinv)
当我运行它并尝试拿起一些东西时,我收到了这个错误:
Traceback (most recent call last):
File "H:/Year 10/Computing/A453/Python Programs/inventory.py", line 15, in <module>
newinv=inventory+str(add)
TypeError: can only concatenate list (not "str") to list
有没有人解决这个问题,将不胜感激。