1.#Write a function to calculate the total value of some changes -
2.# quarters, dimes, nickels, and pennies.
The function should return the total value of the coins.
Then write a program that calls the function.
3.#做一個可以計算所有零錢(quarter,dime,nickel和penny)的價值的function。
4.#那個function應該返回那些硬幣的價值。
5.def money(quarter, dime, nickel, penny):
6..#創造一個function,叫money。有五個參數,分別是quarter,dime,nickel和penny
7. total_quarters = 25*float(quarter)#total_quarters等於25乘參數quarter
8. total_dimes = 10*float(dime)#total_dimes等於10乘參數dime
9. total_nickles = 5*float(nickel)#total_nickels等於5乘參數nickel
10. total_pennies = float(penny)#total_pennies等於25乘參數penny
11. total_money = (total_quarters + total_dimes + total_nickles + total_pennies)/100
12. #total_money等於 total_quarters加上 total_dimes加上 total_nickles加上 total_pennies,
13.#再除以100。
14. print('total money is $',total_money)
15.
16.quarters = str(input('quarters:'))#讓玩家寫有幾個quarter
17.dimes = str(input('dimes:'))#讓玩家寫有幾個
18.nickels = str(input('nickels:'))#讓玩家寫有幾個nickel
19.pennies = str(input('pennies:'))#讓玩家寫有幾個penny
20.money(quarters, dimes, nickels, pennies)#使用functio
運行結果: