1 # coding=gbk 2 def make_great(magician_names,completed_names): 3 """对魔术师列表进行修改,在每个魔术师名字前面加入“the Great”""" 4 while magician_names: 5 curreent_name = magician_names.pop() 6 curreent_name = "the Great " + curreent_name.title() 7 completed_names.append(curreent_name) 8 magician_names = completed_names[:] 9 10 def show_magicians(magician_names): 11 """打印出每个魔术师的名字""" 12 print("\nThe following magicians' name have been printed") 13 for magician in magician_names: 14 print(magician.title()) 15 16 #创建加入字样的空列表和原始名字的列表 17 completed_names = [] 18 magician_names = ['yu peng','xu xinbao','wanglei'] 19 20 make_great(magician_names,completed_names) 21 show_magicians(magician_names)
在命令窗口按Ctrl C,出现下面代码,应该是20行和6行有问题吧。
之后,我又重新敲了一遍,改了一些,运行通过了,但是自己也不知道上面程序错误在什么地方,改完之后代码如下
# coding=gbk def make_great(magician_names,add_great_names): """对列表中的每个魔术师名字中加入‘the Great’""" while magician_names: current_name = magician_names.pop() current_name = "the Great " + current_name.title() add_great_names.append(current_name) return add_great_names def show_magicians(magicians_names): """打印出每个魔术师的名字""" print("\nThe following magicians' name have been printed") for magician in magicians_names: print(magician.title()) #创建一个魔术师名字列表和空的已加字样列表 magician_names = ['yu peng','xu xinbao','wanglei'] add_great_names =[] magician_names = make_great(magician_names,add_great_names) show_magicians(magician_names)
希望各位路过的,帮我看看
很明显有一个死循环,停下来的时候那个20行和6行是指示的你中断的位置。
需要在这两个地方设置中断点debug吗
刚debug了下,确实有个死循环,会一直在‘wang lei’前面加‘the Great’
我觉得20行这里是不是要用可变参数,就是加*的那种?具体的也说不清楚,建议debug调试看值到底传入了没有
谢谢你的回答,debug不会,我自己百度下