笨方法学习Python 习题19 函数和变量 ---学习记录
2017-12-14 09:28
645 查看
习题19 函数和变量
#定义cheese_and_crackers函数,参数有括号里的俩def cheese_and_crackers(cheese_count,boxes_of_crackers):
print “1.You have %d cheeses” % cheese_count
print “2.You have %d boxes of crackers!” % boxes_of_crackers
print “3.Man that’s enough for a party!\n4.Get a blanket.”
开始第一次调用,使用函数cheese_and_crackers的20 30值打印 5 1234
print “5.We can just give the function numbers directly:”cheese_and_crackers(20,30)
开始第二次调用,使用函数cheese_and_crackers的10 50值打印 6 1234
print “6.OR,we can use variable from our script:”amount_of_cheese = 10
amount_of_crackers = 50
cheese_and_crackers(amount_of_cheese,amount_of_crackers)
开始第三次调用,使用函数cheese_and_crackers的30 11值打印 7 1234
print “7.We can even do math inside too:”cheese_and_crackers(10+20,5+6)
开始第四次调用,使用函数cheese_and_crackers
print “8.And we can combine the two,variable and math:”cheese_and_crackers(amount_of_cheese+100,amount_of_crackers+1000)
def cheese_and_crackers(cheese_count,boxes_of_crackers):
print “1.You have %s cheeses” % cheese_count
print “2.You have %s boxes of crackers!” % boxes_of_crackers
print “3.Man that’s enough for a party!\n4.Get a blanket.”
开始第一次调用,使用函数cheese_and_crackers的20 30值打印 5 1234
print “5.We can just give the function numbers directly:”cheese_and_crackers(20,30)
开始第二次调用,使用函数cheese_and_crackers的10 50值打印 6 1234
print “6.OR,we can use variable from our script:”amount_of_cheese = 10
amount_of_crackers = 50
cheese_and_crackers(amount_of_cheese,amount_of_crackers)
开始第三次调用,使用函数cheese_and_crackers的30 11值打印 7 1234
print “7.We can even do math inside too:”cheese_and_crackers(10+20,5+6)
开始第四次调用,使用函数cheese_and_crackers
print “8.And we can combine the two,variable and math:”cheese_and_crackers(amount_of_cheese+100,amount_of_crackers+1000)
开始第五次调用,使用raw_input
print “9. please input your favorite number:”number1 = raw_input(‘>’)
number2 = raw_input(‘>’)
cheese_and_crackers(number1,number2)
开始第六次调用,使用write
print “9. we will use write method to list those:”from sys import argv
script,filename = argv
test = open(filename,’w’)
line1 = raw_input(‘>’)
line2 = raw_input(‘>’)
test.write(line1+’\n’+line2+’\n’)
cheese_and_crackers(line1,line2)
test.close()
开始第七次调用 使用 read—-写不出来啦
相关文章推荐
- 笨方法学习Python-习题19: 函数和变量
- 笨方法学习Python 习题21 函数可以返回东西 ---学习记录
- 笨方法学Python 习题 19: 函数和变量
- 笨方法学习Python-习题18: 命名、变量、代码、函数
- 本方法学python 习题24(综合练习) 习题25(更多关于函数和变量的练习)习题26(修改程序)
- 笨方法学习Python-习题20: 函数和文件
- 笨方法学习Python-习题21: 函数可以返回东西
- Python 函数与变量--习题19,learn python the hard way
- 笨方法学习Python-习题4:变量(variable)和命名
- 笨办法学python习题19 函数和变量
- python 笔记 函数和变量 《笨办法学Python》习题19 ——12.27
- Learn Python The Hard Way学习(19) - 函数和变量
- Python学习19:函数和变量 Function and variables
- 笨方法学习Python-习题35: 分支和函数
- 笨方法学Python 习题 18: 命名、变量、代码、函数
- JavaScript学习记录day6-函数变量作用域、解构赋值与方法
- JavaScript学习记录day6-函数变量作用域、解构赋值与方法
- 笨方法学习Python-习题13: 参数、解包、变量
- 静态方法 分类: python基础学习 2014-04-05 19:34 228人阅读 评论(0) 收藏
- python学习笔记11(函数二): 参数的传递、变量的作用域