动手试一试,函数

9.创建一个魔术师列表,将其 传递给一个函数,这个函数打印列表中每一个魔术师的名字

magicianslist=['lucky','jack','jackson','jobs']
def show_magicians(names):
    for name in names:
        print(name.title())
show_magicians(magicianslist)

10.依据上一个列表,编写一个函数,对列表进行修改,在每个魔术师名字中都加入字样‘the  Great’。调用那个打印的函数,确认魔术师列表确实改变了

magicianslist=['lucky','jack','jackson','jobs']
marklist=[]
def mark_great(list):
    while magicianslist:
        popitem=magicianslist.pop()
        popitem='the Great '+popitem
        marklist.append(popitem)
        marklist.reverse()
mark_great(magicianslist)
def show_magicians(names):
    for name in names:
        print(name.title())
show_magicians(marklist)

11.创建一个列表副本,可以使用两个列表调用函数,一个是修改的,一个是没有修改的

magicianslist=['lucky','jack','jackson','jobs']
magicianslistcopy=magicianslist[:]
marklist=[]
def mark_great(list):
    while magicianslist:
        popitem=magicianslist.pop()
        popitem='the Great '+popitem
        marklist.append(popitem)
        marklist.reverse()
mark_great(magicianslist)
def show_magicians(names):
    for name in names:
        print(name.title())
show_magicians(marklist)
def show_magicians(names):
    for name in names:
        print(name.title())
show_magicians(magicianslistcopy)

 

posted @ 2018-01-05 14:12  xusuns  阅读(118)  评论(0编辑  收藏  举报