本章节,我只是把所有的输出加上了自己的注释。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def cheese_and_crakers(cheese_count, boxes_of_crackers):
'''定义了cheese_and_crakers的函数
读出两个变量,并输出他们。
'''
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_crakers(20,30)
#也可以把相关变量带入这个函数,前提是需要是数字。因为格式化输出时,给的是%d.
print "OR, We can use variables from our script:"
amount_of_cheese = 10
amount_of_crackers = 50
cheese_and_crakers(amount_of_cheese,amount_of_crackers)
#也可以使用运算
print "We can even do math inside too:"
cheese_and_crakers(10+2, 5+6)
#也可以使用变量进行运算。
print "And we can combine the two,variables and math:"
cheese_and_crakers(amount_of_cheese + 100, amount_of_crackers + 1000)