Python入门习题大全——了不起的魔术师

Python入门习题大全——索引

在你为完成练习“魔术师”而编写的程序中,编写一个名为make_ great()的函数,对魔术师列表进行修改,在每个魔术师的名字中都加入字样“theGreat”。调用函数show_magicians(), 确认魔术师列表确实变了。

# 了不起的魔术师
def make_great(names):
    names = ["the great " + name for name in names]
    return names
def show_magicians(names):
    for name in names:
        print(name)

names = ['ling', 'hui', 'he']
names = make_great(names)
show_magicians(names)

输出为:

the great ling
the great hui
the great he

你可能感兴趣的:(Python习题)