运维开发网

方法练习2 - 计算所有零钱(quarter,dime,nickel和penny)的价值

运维开发网 https://www.qedev.com 2021-01-14 11:55 出处:51CTO 作者:mb5ff2f24b42377
1.#Writeafunctiontocalculatethetotalvalueofsomechanges-2.#quarters,dimes,nickels,andpennies.Thefunctionshouldreturnthetotalvalueofthecoins.Thenwriteaprogramthatcallsthefunction.3.#做一个可以计算所有零钱(quarter,
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

运行结果:

方法练习2 - 计算所有零钱(quarter,dime,nickel和penny)的价值

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号