45
45
}
46
46
}
47
47
48
- profit = 0
48
+ profit = 0.0
49
49
50
50
def print_report ():
51
51
print (f"Water: { resources ['water' ]} ml" )
@@ -72,35 +72,42 @@ def accept_money():
72
72
73
73
def is_amount_sufficient_for (drink_name , accepted_amount ):
74
74
cost_for_drink = menu [drink_name ]['cost' ]
75
- print (cost_for_drink )
76
75
if (cost_for_drink > accepted_amount ):
77
76
return False
78
77
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 )} " )
79
83
return True
80
84
81
85
82
86
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
+
85
92
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
97
110
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