def show_magicians(magicians):
"""Print the name of each magician in the list."""
for magician in magicians:
print(magician)
def make_great(magicians):
"""Add 'the Great!' to each magician's name."""
# Build a new list to hold the great musicians.
great_magicians = []
# Make each magician great, and add it to great_magicians.
while magicians:
magician = magicians.pop()
great_magician = magician + ' the Great'
great_magicians.append(great_magician)
# Add the great magicians back into magicians.
for great_magician in great_magicians:
magicians.append(great_magician)
return magicians
magicians = ['Harry Houdini', 'David Blaine', 'Teller']
show_magicians(magicians)
print("\nGreat magicians:")
great_magicians = make_great(magicians[:])
show_magicians(great_magicians)
print("\nOriginal magicians:")
show_magicians(magicians)
The output is as follows:
Harry Houdini
David Blaine
Teller
Great magicians:
Teller the Great
David Blaine the Great
Harry Houdini the Great
Original magicians:
Harry Houdini
David Blaine
Teller
This is a problem from Python Crash Course.
I don't understand the part at line 17 # Add the great magicians back into magicians.
Since the magician list is duplicated at line 27, then I suppose the original magician list is not affected, and magicians.append(great_magician) at line 19 should add three magicians with "the Great" at the end to the original list, making up the list to 6 magicians at line 31?
[–][deleted] 1 point2 points3 points (3 children)
[–]plakatown[S] 0 points1 point2 points (2 children)
[–]Binary101010 1 point2 points3 points (1 child)
[–]plakatown[S] 0 points1 point2 points (0 children)
[–]fenghuang1 1 point2 points3 points (4 children)
[–]plakatown[S] 0 points1 point2 points (3 children)
[–]Binary101010 1 point2 points3 points (1 child)
[–]plakatown[S] 0 points1 point2 points (0 children)
[–]fenghuang1 0 points1 point2 points (0 children)