Мой код выглядит следующим образом:
Код: Выделить всё
def algorithm():
denominations = [5, 2, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01]
numbers_of_denominations = [2, 1, 10, 10, 20, 10, 20, 50]
change = 9.39
i = 0
while(change > 0):
if(change >= denominations[i]):
number_of_coins = int((change / denominations[i]))
change = round(change - denominations[i] * number_of_coins, 2)
print(denominations[i], "x", number_of_coins)
i += 1
Я не знаю, как реализовать границы за монеты.
например, если бы у меня было:
- 5$ x 2
- 2$ x 1
- 0,5$ x 10
- 0,2$ x 10
- 0,1$ x 20
- 0,05$ x 10
- 0,02$ x 20
- 0,01$ x 50
Текущая добыча это:
Код: Выделить всё
5$ x 1
2$ x 2
0.2$ x 1
0.1$ x 1
0.05$ x 1
0.02$ x 2
Подробнее здесь: https://stackoverflow.com/questions/609 ... ate-bounds
Мобильная версия