-
Notifications
You must be signed in to change notification settings - Fork 2
/
coffee_machine.py
48 lines (37 loc) · 1.11 KB
/
coffee_machine.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#coffee machine
import emojis
coffee_emoji = emojis.encode(":coffee:")
tea_emoji = emojis.encode(":tea:")
money = 0
coffee_price = 40
tea_price = 30
products_list = {'1':coffee_price,'2':tea_price}
def ask_buyer():
return int(input("add money to buy: "))
def choose_product():
print('*'*10)
print("1- Coffee\n2- tea")
return input("What do you want to buy: ")
def sell_product(money,products_list,product_to_buy):
while money<products_list[product_to_buy]:
money_needed = products_list[product_to_buy] - money
print(f"no enough money, you need {money_needed}")
money_added = ask_buyer()
money += money_added
if product_to_buy=='1':
print(f"here is your Coffee {coffee_emoji}")
else:
print(f"here is your Tea {tea_emoji}")
money = money-products_list[product_to_buy]
return money
def show_money_left(money,products_list,product_to_buy):
if money!=0:
print(f"here is your money left {money}")
else:
print("no money left")
def main():
money = ask_buyer()
product = choose_product()
money_left = sell_product(money, products_list, product)
show_money_left(money_left,products_list,product)
main()