Tôi đang cố gắng tạo một chương trình kiểm kê để sử dụng trong trò chơi RPG. Chương trình cần có thể thêm và xóa mọi thứ và thêm chúng vào danh sách. Đây là những gì tôi có cho đến nay:LoạiError: chỉ có thể nối danh sách (không phải "str") vào danh sách
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)
Khi tôi chạy này và cố gắng chọn một số điều lên, tôi nhận được lỗi này:
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
Có ai có cách khắc phục cho điều này, sẽ là đáng kể đánh giá cao