美文网首页
8.4传递列表

8.4传递列表

作者: user_Js | 来源:发表于2020-04-18 12:25 被阅读0次

    传递列表

    def greet_users(names):
    """像列表中的每位用户发出问候"""
    for name in names:
    msg = "Hello, " + name.title() + "!"
    print(msg)

    usernames = ['js','jzh','jjf']
    greet_users(usernames)


    image.png

    在函数中修改列表

    def print_models(unprinted_designs,completed_models):
    """
    打印每个设计,直到没有未打印的设计为止
    打印每个设计后,都将其移到列表completed_models中
    """
    while unprinted_designs:
    current_design = unprinted_designs.pop()

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

    def show_completed_models(completed_models):
    """显示打印好的模型"""
    print("\nThe following models have been printed:")
    for completed_model in completed_models:
    print(completed_model)

    unprinted_designs = ['iphone case','robot pendant','dodecahedron']
    completed_models = []

    print_models(unprinted_designs,completed_models)
    show_completed_models(completed_models)


    image.png

    魔术师

    def show_magicians(names):
    """打印每位魔术师的名字"""
    for name in names:
    print(name)

    m_name = ['js','jzh','jjf']
    show_magicians(m_name)


    image.png

    def show_magicians(names):
    """打印每位魔术师的名字"""
    for name in names:
    print(name)

    def make_great(names):
    great_magicians = []

    while names:
        name = names.pop()
        great_magician = name + " the Great"
        great_magicians.append(great_magician)
        
    for great_magician in great_magicians:
        print(great_magician)
    

    names = ['js','jzh','jjf']
    show_magicians(m_name)

    make_great(names)
    show_magicians(names)


    image.png

    相关文章

      网友评论

          本文标题:8.4传递列表

          本文链接:https://www.haomeiwen.com/subject/ssbyuhtx.html