-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (33 loc) · 1.09 KB
/
main.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
def calculate_change():
available_money = [20, 20, 50, 5, 5, 100]
ticket_price = int(input("Ticket price ?:"))
payment = int(input("Payment ?:"))
change = payment - ticket_price
available_money.sort()
available_money.reverse()
change_money = calculate_money(change, available_money.copy())
total_change = sum(change_money)
if total_change == change:
print("change: ", change, "\nmoneys: ", change_money)
else:
print("Not enough change, available moneys: ", available_money)
def calculate_money(amount, moneys):
result = []
for m in moneys:
if amount >= m:
result.append(m)
break
if len(result) > 0:
amount = amount - result[0]
moneys.remove(result[0])
_result = calculate_money(amount, moneys)
result = result + _result
return result
else:
return []
if __name__ == '__main__':
continue_ = 1
while continue_ == 1:
calculate_change()
continue_ = int(input("Repeat ? 1/0:"))
# See PyCharm help at https://www.jetbrains.com/help/pycharm/