Результат я ищу: 6,9
6,9 это сумма 2,5 + 1 + 3 + 0,40. Я хочу написать код, чтобы при каждом изменении количества каждой монеты переменная dollar_amount обновлялась с правильной суммой.
def calc_dollars(quarter, nickels, dimes, pennies):
piggy_bank = {
"quarters":10, #this is 10 quarters, which is 2.5
"nickels":20, #this is 20 nickels, which is 1
"dimes":30, #this is 30 dimes, which is 3
"pennies":40 #this is 40 pennies, which is .40
}
for quarters, v in piggy_bank.items():
quarters = v * 0.25
for nickels, v in piggy_bank.items():
nickels = v * 0.05
for dimes, v in piggy_bank.items():
dimes = v * 0.10
for pennies, v in piggy_bank.items():
pennies = v * 0.01
dollar_amount = sum(quarters, nickels, dimes, pennies)
print(dollar_amount)