《笨办法学
python
》学习笔记(
Python 3.6
)
习题
19 ex19.py
# -*- coding: utf-8 -*-
#
定义
cheese_and_crackers
这个函数
,
该函数有两个参数,分别是
cheese_count
和
boxes_of_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 directy:")
#
调用了这个函数,带入两个参数(
20, 30
)
cheese_and_crackers(20,30)
print("OR,we can use variables from our script:")
#
定义两个变量
amount_of_cheese=10
amount_of_crackers=50
#
将定义的两个变量作为参数引入到函数中。
cheese_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)
#
自编练习
1
def my_exercise_prg(prg1,prg2):
print("The fisrt number is %d." %prg1)
print("The second number is %d."%prg2)
print("The first number and the second number equals " ,end="")
print(prg1+prg2,".")
print("Let's do math!")
prg1=2
prg2=7
my_exercise_prg(prg1,prg2)
#
自编练习
2