首页 > 编程语言 > 详细

笨办法学python3练习代码ex19.py

时间:2020-07-18 14:22:44      阅读:47      评论:0      收藏:0      [点我收藏+]

定义函数的语法:

    def  函数名(参数)

      (语句)

 1 #函数和变量
 2 #函数里的变量与脚本里的变量是没有联系的。
 3 def cheese_and_crackers(cheese_count,boxes_of_crackers):
 4     print(f"You have {cheese_count} cheese!")
 5     print(f"You have {boxes_of_crackers} boxes of crackers!")
 6     print("Man that‘s enough for a party!")
 7     print("Get a blanket.\n")    #blanket :毛毯
 8     
 9     
10 print("We can just give the function numbers directly: ")
11 cheese_and_crackers(20,30)
12 
13 
14 print("OR, We can use variables from our script:")
15 amount_of_cheese = 10
16 amount_of_crackers =50
17 cheese_and_crackers(amount_of_cheese,amount_of_crackers)
18 
19 
20 print("We can even do math inside too: ")
21 cheese_and_crackers(10 + 20, 5 + 6)
22 
23 
24 print("And we can combine the two, variable and math: ")
25 cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)

 

笨办法学python3练习代码ex19.py

原文:https://www.cnblogs.com/lsc666js/p/13334714.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!