Python编程从入门到实践 8-10

8-11 不变的魔术师 不变的魔术师 :修改你为完成练习8-10而编写的程序,在调用函数make_great() 时,向它传递魔术师列表的副本。由于不想修改原始列表,请返回修改后的 列表,并将其存储到另一个列表中。分别使用这两个列表来调用show_magicians() ,确认一个列表包含的是原来的魔术师名字,而另一个列表包含的是添加了字 样“the Great”的魔术师名字。

def make_great(f_magician_name):
    new_magician_name = []
    for name in f_magician_name:
        name += " the Great"
        new_magician_name.append(name)
    return new_magician_name


def show_magicians(f_magician_name):
    for name in f_magician_name:
        print("Magician is " + name)


magician_names = ['1', '2', '3', '4']

new_magician_names = make_great(magician_names[:])
show_magicians(magician_names)
show_magicians(new_magician_names)


你可能感兴趣的:(Python编程从入门到实践 8-10)