定义函数,大神帮忙看下哪里错了

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

def make_great(magicians):
    great_magicians = []
    while magicians:
        new_magician = magicians.pop()
        great_magician = "the great " + new_magician
        great_magicians.append(great_magician)
    print(great_magicians)

magician_list = ['ada1', 'jack1', 'mai1','tom1']
check_great = make_great(magician_list)
#print(check_great)
show_magicians(check_great)
TypeError: 'NoneType' object is not iterable

为什么会报错?

为什么print(check_great)会返回none?

make_great生成的列表为什么无法赋值给到check_great?

我的目的是调用show_magicians函数打印出make_great函数生成的列表,应该怎样实现呢?


极限开水
浏览 814回答 3
3回答

慕后端443704

# 一共两处错误,已经在代码里标注了,下列代码实测可运行,应该能达到你的效果def show_magicians(magicians):    for magician in magicians:        print(magician)       # 你没有缩进 def make_great(magicians):    great_magicians = []    while magicians:        new_magician = magicians.pop()        great_magician = "the great " + new_magician        great_magicians.append(great_magician)    return great_magicians    # print是没有返回值的,要用return magician_list = ['ada1', 'jack1', 'mai1','tom1']check_great = make_great(magician_list)#print(check_great)show_magicians(check_great)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python