1 定义一个函数,可以如图输出,并且设计一个可以反复调用的程序。
image.png
# -*- coding:utf-8 -*-
def printMyNameBig():
print"WWW WW WWW RRRR"
print" WW WW WW R R"
print" WW WW WW R R"
print" W WW W RRRR"
print" W W R R"
print" W W R R"
for i in range(5):
printMyNameBig()
学习体会:一开始还挺疑惑字母要怎么可以显示成如图的样子,我就写“w”*5,这样的写法,肯定是输出不出来的,所以这题是看了答案了,反复调用,加入循环就可以。
- 2 定义一个打印多个元素的函数
#define a function with seven arguments
def printAddr(name,num,street,city,prov,pcode,country):
print name
print num,
print street
print city,
if prov !="":
print ", "+prov
else:
print ""
print pcode
print country
print
#call the function and pass seven argu,ment to it
printAddr("Sam","45","Main st.","Ottawa","ON","K2M 2E9","Canada")
printAddr("Jian","64","2nd Ave.","Hong Kong","","235643","china")
Sam
45 Main st.
Ottawa , ON
K2M 2E9
Canada
Jian
64 2nd Ave.
Hong Kong
235643
china
参考了答案
网友评论