python_函数传递列表

'''
#创建一个空列表,包含一些要打印的设计
unprinted_designs = ['iphone','robot','books']
completed_modles = []

#模拟打印每个设计,直到没有未打印的设计为止
while unprinted_designs:
current_design = unprinted_designs.pop()

#模拟根据设计制作3D打印模型的过程
print("Printing model:"+current_design)
completed_modles.append(current_design)

#显示打印好的所有模型
print('\n The following models have been printed:')
for completed_modle in completed_modles:
print(completed_modle)
#print(completed_modles)
print(unprinted_designs)

'''
--------------------------------------------------------------------------------------------------------------------
#定义两个函数,函数1:负责处于打印设计的工作,函数2:概述打印了哪些设计

# unprinted_designs = ['iphone','robot','books']
# completed_modles = []
def print_models(unprinted_designs): #定义打印设计的函数,包含两个形参:一个需要打印的设计列表和一个打印好的模型列表
"""
模拟打印每个设计,直到没有未打印的设计为止
打印每个设计后,都将其移动到列表completed_models中
:param unprinted_designs:
:param completed_models:
:return:
"""
while unprinted_designs:
current_design= unprinted_designs.pop()


#模拟根据设计制作3D打印模型的过程
print("Printing model:"+current_design)
completed_models.append(current_design)
for unprinted_design in unprinted_designs:
print("Unprinted:"+unprinted_design)

 

def show_completed_models(completed_models): #定义展示已打印的函数,包含一个形参:打印好的模型列表
"""显示打印的所有模型"""
print("\nThe following models have been printed:")

for completed_modle in completed_models:
print(completed_modle)

unprinted_designs = ['iphone','robot','books'] #传递两个列表
completed_models = []

print_models(unprinted_designs[:]) #调用打印函数和展示函数 [:]建立副本可保留原始列表的内容
show_completed_models(completed_models)
# print("Unprinted:"+unprinted_designs)

posted @ 2019-03-07 16:54  Monica001  阅读(538)  评论(0编辑  收藏  举报