笨方法学习Python 习题19 函数和变量 ---学习记录

习题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—-写不出来啦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值