传递列表

作者: 庵下桃花仙 | 来源:发表于2018-11-08 22:13 被阅读2次
    # 8-9
    def show_magicians(magicians):
        """打印每个魔术师名字"""
        for magician in magicians:
            print(magician.title())
    
    magicians = ['david stone', 'dan &dave', 'david copperfield']
    show_magicians(magicians)
    
    # 8-10
    def show_magicians(magicians):
        """打印每个魔术师名字"""
        for magician in magicians:
            print(magician.title())
    
    def make_great(magicians):
        """名字前加'the Great'"""
        length = len(magicians)
        for i in range(1, length+1):
            magicians[i-1] = 'the Great ' + magicians[i-1]
    
    magicians = ['david stone', 'dan &dave', 'david copperfield']
    show_magicians(magicians)
    make_great(magicians)
    show_magicians(magicians)
    
    # 8-11
    def show_magicians(magicians):
        """打印每个魔术师名字"""
        for magician in magicians:
            print(magician.title())
    
    def make_great(magicians):
        """名字前加'the Great'"""
        length = len(magicians)
        for i in range(1, length+1):
            magicians[i-1] = 'the Great ' + magicians[i-1]
        return(magicians)
    
    magicians = ['david stone', 'dan &dave', 'david copperfield']
    show_magicians(magicians)
    magicians_new = make_great(magicians[:])
    show_magicians(magicians_new)
    show_magicians(magicians)
    
    David Stone
    Dan &Dave
    David Copperfield
    David Stone
    Dan &Dave
    David Copperfield
    The Great David Stone
    The Great Dan &Dave
    The Great David Copperfield
    David Stone
    Dan &Dave
    David Copperfield
    The Great David Stone
    The Great Dan &Dave
    The Great David Copperfield
    David Stone
    Dan &Dave
    David Copperfield
    

    相关文章

      网友评论

        本文标题:传递列表

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