函数的练习2——python编程从入门到实践

8-9 魔术师:创建一个包含魔术师名字的列表,并将其传递一个名为show_magicians()的函数,这个函数打印列表中每个魔术师的名字。

def show_magicians(magicians):
for magician in magicians:
print(magician)


magicians = ['magician_A', 'magician_B', 'magician_C']
show_magicians(magicians)

8-10 了不起的魔术师:在8-9的程序中,编写一个名为make_great()的函数,对函数列表进行修改,在每个魔术师的名字中都加入字样“the Great”。调用函数show_magicians(),确认魔术师列表确实变了。

def make_great(magicians):
for i in range(len(magicians)):
magicians[i] = "The Great " + magicians[i]


make_great(magicians)
show_magicians(magicians)

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

def show_magicians(magicians):
    for magician in magicians:
        print(magician)


def make_great(magicians):
    for i in range(len(magicians)):
        magicians[i] = "The Great " + magicians[i]


magicians = ['magician_A', 'magician_B', 'magician_C']
make_great(magicians[:])
show_magicians(magicians)
make_great(magicians)
show_magicians(magicians)

   这段代码应该是符合题意的吧???纠结了一晚上了,不管了,有大神看到的话,给个结论呗,谢谢啦。。。

点赞