我编写了这段代码来打印“魔术师”列表中的名字。
def show_magicians(mag_names):
print("Here is the name of the magicians")
print("The old list is :", mag_names)
while mag_names:
full_name = mag_names.pop()
printed_list.append(full_name.title())
print("The name of the magician is ", full_name.title())
print("The old list now :", mag_names)
print("The new list is :", printed_list)
magicians = ['houdini', 'williams', 'sunderland']
printed_list = []
show_magicians(magicians)
我的 for 循环代码
for magician in mag_names:
full_name = mag_names.pop()
printed_list.append(full_name.title())
如果我使用while循环执行,则代码可以在打印每个名称时正常工作,但使用for循环时,列表的第一个元素不会按预期打印。
森林海
HUH函数
阿波罗的战车
相关分类