Skip to content

Commit 5f52311

Browse files
committed
update programm 33
1 parent af67e51 commit 5f52311

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

015-day/Program33.py

+31-24
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
}
4646
}
4747

48-
profit = 0
48+
profit = 0.0
4949

5050
def print_report():
5151
print(f"Water: {resources['water']}ml")
@@ -72,35 +72,42 @@ def accept_money():
7272

7373
def is_amount_sufficient_for(drink_name, accepted_amount):
7474
cost_for_drink = menu[drink_name]['cost']
75-
print(cost_for_drink)
7675
if(cost_for_drink > accepted_amount):
7776
return False
7877
else:
78+
balance = accepted_amount - cost_for_drink
79+
global profit
80+
profit += cost_for_drink
81+
if(balance > 0):
82+
print(f"You have balance ${round(balance,2)}")
7983
return True
8084

8185

8286
def make_drink(drink_name):
83-
print('Enjoy the drink')
84-
87+
ingradients = menu[drink_name]['ingredients']
88+
for key in ingradients:
89+
resources[key] -= ingradients[key]
90+
print(f"Please enjoy {drink_name}")
91+
8592

86-
user_input = input("What would you like? (espresso/latte/cappuccino): ")
87-
is_sufficient = is_suffient_resources(user_input)
88-
if(user_input == 'espresso' or user_input == 'latte' or user_input == 'cappuccino'):
89-
if(is_sufficient):
90-
print('Availa')
91-
accepted_amount = accept_money()
92-
print(f"accepted money: {accepted_amount}")
93-
is_sufficient_amount = is_amount_sufficient_for(user_input, accepted_amount)
94-
if(is_sufficient_amount):
95-
print('Amount enough')
96-
make_drink()
93+
def run_machine():
94+
is_on = True
95+
while(is_on):
96+
choice = input("What would you like? (espresso/latte/cappuccino): ")
97+
if(choice == 'espresso' or choice == 'latte' or choice == 'cappuccino'):
98+
if(is_suffient_resources(choice)):
99+
accepted_amount = accept_money()
100+
if(is_amount_sufficient_for(choice, accepted_amount)):
101+
make_drink(choice)
102+
else:
103+
print('Amount is not sufficient.')
104+
else:
105+
print('Sorry, resources not available.')
106+
elif(choice == 'report'):
107+
print_report()
108+
elif(choice == 'off'):
109+
is_on = False
97110
else:
98-
print('Amount not enough refund')
99-
else:
100-
print('Sorry not avail')
101-
elif(user_input == 'report'):
102-
print_report()
103-
elif(user_input == 'off'):
104-
exit
105-
else:
106-
print('Not a valid input')
111+
print('Not a valid input')
112+
113+
run_machine()

0 commit comments

Comments
 (0)