shop.py

Created by naul

Created on May 02, 2023

885 Bytes


def shop():
    items = {
        "health_potion": 10,
        "mana_potion": 20,
        "sword": 50,
        "armor": 100
    }
    
    print("Welcome to the shop!")
    print("Here are the items for sale:")
    
    for item, price in items.items():
        print(f"{item.capitalize()}: {price} gold")
        
    choice = input("What would you like to do? (buy/sell/leave) ")
    
    if choice == "buy":
        item_choice = input("What would you like to buy? ")
        if item_choice in items:
            item_price = items[item_choice]
            # code to deduct gold and add item to player's inventory
        else:
            print("That item is not for sale.")
    elif choice == "sell":
        # code to sell items from player's inventory and add gold
    elif choice == "leave":
        return
    else:
        print("Invalid choice.")
        shop()