PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
products = {1: "Soda", 2: "Sprite", 3:"Coke", 4:"Cheetos", 5:"Doritos", 6:"Lays"}
pcost = {1: 0.50, 2: 0.50, 3: 0.75, 4: 1.25, 5: 1.25, 6: 1.50}
plist = ("Soda -- 1", "Sprite -- 2", "Coke -- 3", "Cheetos -- 4", "Doritos -- 5", "Lays -- 6")
bought = []
global money
money = 5.00
'''
Hi, thanks for viewing this code. Unfortunately this code will not run
in the way intended in the Sololearn playground. You may run this code
with this link.
https://www.programiz.com/python-programming/online-compiler/
'''
def setmoney(cost, pname, add): # Subtracts the cost of the chosen item from user's money and prints the product name
global money
if money >= pcost[cost]:
money -= pcost[cost]
bought.append((products[add]))
print("You have received", products[pname])
print("You have $" + str(money), "left.")
else:
print("You do not have enough money.")
def welcome(): # Shows a welcome message and the products available to purchase
print("Welcome to this vending machine!")
for i in plist[0:]:
print(i)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run