I am trying to make an inventory program to use in an RPG. The program needs to be able to add and remove things and then add them to a list. This is what I have so far:
inventory=["sword","potion","armour","bow"]
print(inventory)
print("
commands: 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)
When I run this and try to pick something up, I get this error:
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
Does any one have a fix for this, it would be greatly appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…