This question already has an answer here:
This is just a start to setting up a little shop. I created a dictionary that has the shops inventory, and their price.
Now I want the user to choose one of the items to buy. As you can see I've just started on the if statement. Any idea how I can basically say - if user selects an item from the dictionary, remove this from the dictionary, add the item to the user inventory, and remove that much gold from their wallet?
user_inventory = []
shop_inventory = {'kettle:':3,'lunchbox:':4,'squirrel:':1}
user_wallet = 10
shopping = True
def inventory():
for i in shop_inventory:
print(i, shop_inventory[i],'gold')
while shopping == True:
print('We have: ')
inventory()
print('You have: ',user_wallet,' gold.')
user_choice = input('What would you like to buy? ')
if user_choice == shop_inventory():
print('Huzzahhh')
Aucun commentaire:
Enregistrer un commentaire