I have written this code to print the names in the list 'magicians'.
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)
My for loop code
for magician in mag_names:
full_name = mag_names.pop()
printed_list.append(full_name.title())
If I execute with while loop the code works fine with every name printed but with for loop the first element of the list is not printed as intended.
whileloop for this task looks perfectly reasonable to me. So why do you want to use aforloop?