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
誰でもこれを修正できますか、それは大歓迎です。