Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python make a shop menu

# this is my own work from a fun project of a text based game I am making

def shopkeep(player_gold, player_inv, general_store_inv):
    for x in range(8):
        print()
    print("Shopkeeper: Welcome to my humble shop for now!")
    time.sleep(0.5)
    shopkeep_leave = False
    while shopkeep_leave is False:
        x2 = 0
        print("
Shopkeeper: Care to peruse my wares?
")
        time.sleep(1)
        print("Shopkeeper: The upgraded sword and shield are 5 gold each, everything else is 2 gold.")
        print("Gold in coin purse: " + str(player_gold))
        for x in general_store_inv:
            time.sleep(0.2)
            print(str(x2 + 1) + ". " + str(general_store_inv[x2]))
            x2 += 1
        shop_purchase = input("""Please select:
            > """)
        if shop_purchase == "":
            shop_purchase = "1"
        int_choice = int(shop_purchase) - 1
        if x2 < 1:
            print("Shopkeeper: Sorry lad, just realised we're out of stock!")
            time.sleep(1)
            print("You leave the store")
            shopkeep_leave = True
            return player_gold, player_inv, general_store_inv
        if int_choice <= x2:
            print("You want to buy: " + str(general_store_inv[int_choice]) + " is this correct?
Y/N")
            confirm = input("   > ")
            if "Y" in confirm.upper():
                if "apple" in str(general_store_inv[int_choice]):
                    if player_gold >= 2:
                        time.sleep(0.5)
                        print("You pay 2g and obtain an apple!")
                        player_inv.append("apple")
                        general_store_inv.remove("apple")
                        player_gold -= 2
                    else:
                        print("Shopkeep: Looks like you can't afford that!")
                elif "sword2" in str(general_store_inv[int_choice]):
                    if player_gold >= 5:
                        time.sleep(0.5)
                        print("You pay 5g and obtain an upgraded sword!")
                        player_inv.append("sword2")
                        general_store_inv.remove("sword2")
                        player_gold -= 5
                    else:
                        print("Shopkeep: Looks like you can't afford that!")
                elif "sword" in str(general_store_inv[int_choice]):
                    if player_gold >= 2:
                        time.sleep(0.5)
                        print("You pay 2g and obtain a basic sword!")
                        player_inv.append("sword")
                        general_store_inv.remove("sword")
                        player_gold -= 2
                    else:
                        print("Shopkeep: Looks like you can't afford that!")
                elif "shield" in str(general_store_inv[int_choice]):
                    if player_gold >= 5:
                        time.sleep(0.5)
                        print("You pay 5g and obtain a shield!")
                        player_inv.append("shield")
                        general_store_inv.remove("shield")
                        player_gold -= 2
                    else:
                        print("Shopkeep: Looks like you can't afford that!")
                elif "brown coat" in str(player_inv[int_choice]):
                    if player_gold >= 2:
                        time.sleep(0.5)
                        print("You pay 2g and obtain a brown coat!")
                        player_inv.append("brown coat")
                        general_store_inv.remove("brown coat")
                        player_gold -= 2
                    else:
                        print("Shopkeep: Looks like you can't afford that!")
            elif confirm == "":
                print("Shopkeeper: I take it you didn't want that then")
                time.sleep(2)
            else:
                confirm = input("Shopkeeper: Do you want to exit?
    > ")
                if "Y" in confirm.upper():
                    shopkeep_leave = True
                    return player_gold, player_inv, general_store_inv

    return player_gold, player_inv, general_store_inv
Comment

PREVIOUS NEXT
Code Example
Python :: undefie int value python 
Python :: how to get more than one word in a list in python 
Python :: how to find the length of a list in scratch 
Python :: python popen no message 
Python :: x= [10] def List_ex(): x.append(20) def add_list(): x=[30,40] x.append(50) print (x) List_ex() print (x) add_list() print (x) 
Python :: th2=cv2.adaptiveThreshold(img, 255 ,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11 # no of block size , 2 #c) 
Python :: numpy get specified colums 
Python :: python spamming bot 
Python :: minimum from list of tuples 
Python :: save plot in python 
Python :: length of list in jinja 
Python :: taking hour information from time in pandas 
Python :: python import upper directory 
Python :: read csv boto3 
Python :: spacy frenc hlemmatizer 
Python :: in 2002 elon musk age 
Python :: datetime python 
Python :: how to move file from one location to another with python 
Python :: importing tkinter in python 
Python :: pd.merge left join 
Python :: how to print a line letter by letter in python 
Python :: somma in python 
Python :: how many data types are specified to numeric values in python 
Python :: how to reverse word order in python 
Python :: removing odd index character of a given string in python 
Python :: browser pop up yes no selenium python 
Python :: reverse order np array 
Python :: how to convert a list into string with  
Python :: python console command 
Python :: Savefig cuts off title 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =