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函数生成的列表,应该怎样实现呢?
3 回答
慕后端443704
TA贡献2条经验 获得超0个赞
# 一共两处错误,已经在代码里标注了,下列代码实测可运行,应该能达到你的效果
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)
添加回答
举报
0/150
提交
取消