习题19 函数和变量
来源:互联网 发布:淘宝宝贝链接怎么发 编辑:程序博客网 时间:2024/06/05 18:17
这一节展示了一个函数 cheese_and_crackers 的各种参数传递方式
def cheese_and_crackers(cheese_count,boxes_of_crackers): print "You have %d cheeses!" % cheese_count print "You have %d boxes of crackers!" % boxes_of_crackers print "Man that's enough for a party!" print "Get a blanket.\n"print "We can just give the function numbers directly:"cheese_and_crackers(20,30)print "OR ,we can use variables from our script:"amount_of_cheese = 10amount_of_crackers = 50cheese_and_crackers(amount_of_cheese,amount_of_crackers)print "We can even do math inside too:"cheese_and_crackers(10+20,5+6)print "And we can combine the two ,variables and math:"cheese_and_crackers(amount_of_cheese + 100,amount_of_crackers + 1000)
我们可以直接给函数传递数字
cheese_and_crackers(20,30)
也可以给变量
cheese_and_crackers(amount_of_cheese,amount_of_crackers)
还可以给数学表达式
cheese_and_crackers(10+20,5+6)
cheese_and_crackers(amount_of_cheese + 100,amount_of_crackers + 1000)=====================================================================================
注意使用 int() 来把 raw_input() 输入的值转化为整数
举例
print "Input how many cheese do you need:"a = raw_input()input_cheese = int(a)print "You need %d cheeses." % input_cheese
0 0
- 习题19 函数和变量
- 笨方法学Python 习题 19: 函数和变量
- 笨方法学习Python-习题19: 函数和变量
- 笨办法学python习题19 函数和变量
- 习题18 命名、变量、代码和函数
- 笨方法学习Python 习题19 函数和变量 ---学习记录
- 习题4 变量和命名
- 习题4--变量和命名
- 本方法学python 习题24(综合练习) 习题25(更多关于函数和变量的练习)习题26(修改程序)
- 笨办法学python习题18 命名、变量、代码和函数
- 变量变量和变量函数
- Exercise 19: 函数和变量
- exercise 19 函数和变量
- 习题5 更多的变量和打印
- 习题13 参数、解包和变量
- 习题5--更多的变量和打印
- 习题13--参数、解包和变量
- 习题35 分支和函数
- pat 1106. Lowest Price in Supply Chain (25)
- 3.2 设计一个程序,要求用户输入 5 个字符,然后将这 5 个字符按相反的顺序显示出 来。例如,假设输入 abcde,则输出为 edcba
- linux通过端口杀进程
- CSS3样式一
- POJ 3984 BFS走迷宫问题
- 习题19 函数和变量
- 关于FileReader无法找到文件原因
- git 使用场景一,pull报错:Auto Merge Failed; Fix Conflicts and Then Commit the Result.
- pat甲级_路径问题(例题:pat 1003 Emergency (25))
- SpringMVC学习:redirect URL中的猫腻
- Android执行定时循环任务
- 缓存-redis
- 8086汇编语言 汇编源程序中使用jmp命令修改IP
- 8086汇编语言 汇编源程序中使用jmp命令修改CS:IP