8-10 了不起的魔术师

时间:2023-02-15 19:52:27

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

# 8-9
magicians = ["老王","猫猫","登登"]
def show_magicians(magicians):
  for magician in magicians:
    print(magician)
show_magicians(magicians)

 

# 8-10

def show_magicians(magicians,new_magicians):
    while magicians:
        current_magicians = magicians.pop()
        current_magicians = "the Great: " + current_magicians
        new_magicians.append(current_magicians)

def make_great(new_magicians):
    for magician in new_magicians:
        print(magician)

magicians = ["老王", "猫猫", "登登"]
new_magicians = []

show_magicians(magicians,new_magicians)
make_great(new_magicians)