zoukankan      html  css  js  c++  java
  • 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(' 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(" The 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)

  • 相关阅读:
    【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳
    【POJ 2187】Beauty Contest 凸包+旋转卡壳
    1056: [HAOI2008]排名系统
    1874: [BeiJing2009 WinterCamp]取石子游戏
    1055: [HAOI2008]玩具取名
    2338: [HNOI2011]数矩形
    1060: [ZJOI2007]时态同步
    1054: [HAOI2008]移动玩具
    1053: [HAOI2007]反素数ant
    1052: [HAOI2007]覆盖问题
  • 原文地址:https://www.cnblogs.com/monica001/p/10490724.html
Copyright © 2011-2022 走看看