python make a shop menu

Solutions on MaxInterview for python make a shop menu by the best coders in the world

showing results for - "python make a shop menu"
Alina
30 Jun 2020
1# this is my own work from a fun project of a text based game I am making
2
3def shopkeep(player_gold, player_inv, general_store_inv):
4    for x in range(8):
5        print()
6    print("Shopkeeper: Welcome to my humble shop for now!")
7    time.sleep(0.5)
8    shopkeep_leave = False
9    while shopkeep_leave is False:
10        x2 = 0
11        print("\nShopkeeper: Care to peruse my wares?\n")
12        time.sleep(1)
13        print("Shopkeeper: The upgraded sword and shield are 5 gold each, everything else is 2 gold.")
14        print("Gold in coin purse: " + str(player_gold))
15        for x in general_store_inv:
16            time.sleep(0.2)
17            print(str(x2 + 1) + ". " + str(general_store_inv[x2]))
18            x2 += 1
19        shop_purchase = input("""Please select:
20            > """)
21        if shop_purchase == "":
22            shop_purchase = "1"
23        int_choice = int(shop_purchase) - 1
24        if x2 < 1:
25            print("Shopkeeper: Sorry lad, just realised we're out of stock!")
26            time.sleep(1)
27            print("You leave the store")
28            shopkeep_leave = True
29            return player_gold, player_inv, general_store_inv
30        if int_choice <= x2:
31            print("You want to buy: " + str(general_store_inv[int_choice]) + " is this correct?\nY/N")
32            confirm = input("   > ")
33            if "Y" in confirm.upper():
34                if "apple" in str(general_store_inv[int_choice]):
35                    if player_gold >= 2:
36                        time.sleep(0.5)
37                        print("You pay 2g and obtain an apple!")
38                        player_inv.append("apple")
39                        general_store_inv.remove("apple")
40                        player_gold -= 2
41                    else:
42                        print("Shopkeep: Looks like you can't afford that!")
43                elif "sword2" in str(general_store_inv[int_choice]):
44                    if player_gold >= 5:
45                        time.sleep(0.5)
46                        print("You pay 5g and obtain an upgraded sword!")
47                        player_inv.append("sword2")
48                        general_store_inv.remove("sword2")
49                        player_gold -= 5
50                    else:
51                        print("Shopkeep: Looks like you can't afford that!")
52                elif "sword" in str(general_store_inv[int_choice]):
53                    if player_gold >= 2:
54                        time.sleep(0.5)
55                        print("You pay 2g and obtain a basic sword!")
56                        player_inv.append("sword")
57                        general_store_inv.remove("sword")
58                        player_gold -= 2
59                    else:
60                        print("Shopkeep: Looks like you can't afford that!")
61                elif "shield" in str(general_store_inv[int_choice]):
62                    if player_gold >= 5:
63                        time.sleep(0.5)
64                        print("You pay 5g and obtain a shield!")
65                        player_inv.append("shield")
66                        general_store_inv.remove("shield")
67                        player_gold -= 2
68                    else:
69                        print("Shopkeep: Looks like you can't afford that!")
70                elif "brown coat" in str(player_inv[int_choice]):
71                    if player_gold >= 2:
72                        time.sleep(0.5)
73                        print("You pay 2g and obtain a brown coat!")
74                        player_inv.append("brown coat")
75                        general_store_inv.remove("brown coat")
76                        player_gold -= 2
77                    else:
78                        print("Shopkeep: Looks like you can't afford that!")
79            elif confirm == "":
80                print("Shopkeeper: I take it you didn't want that then")
81                time.sleep(2)
82            else:
83                confirm = input("Shopkeeper: Do you want to exit?\n    > ")
84                if "Y" in confirm.upper():
85                    shopkeep_leave = True
86                    return player_gold, player_inv, general_store_inv
87
88    return player_gold, player_inv, general_store_inv