Confused about modifying lists using two functions in Python
<p>I'm currently reading <em>Python Crash Course</em> by Eric Matthes and I'm having an incredibly difficult time understanding chapter 8 which is all about functions. I am stuck on exercise 8-10 which asks me to use a new function to change a list used in the previous exercise.</p>

<p>Here is the exercise:</p>

<pre><code>8-9. Magicians: Make a list of magician's names. Pass the list to a function called show_magicians(), which prints the name of each magician in the list.

8-10. Great Magicians: Start with a copy of your program from exercise 8-9. Write a function make_great() that modifies the list of magicians by adding the phrase the great to each magician's name. Call show_magicians() to see that the list has actually been modified.
</code></pre>

<p><strong>Here is my code for 8-9:</strong></p>

<pre><code>def show_magicians(names):
    """Print each magician name"""
    for name in names:
        msg = name.title()
        print(msg)

magician_names = ['sonic', 'tails', 'knuckles']
show_magicians(magician_names)
</code></pre>

<p>I've seen a very similar topic on this website and so I tried to use the code in the first answer on this page to help me out: <a href="http://stackoverflow.com/questions/39338405/python-crash-course-8-10">Python crash course 8-10</a></p>

<p>However, my code still appears to be incorrect as the compiler prints 'the great' 3 times after each name.</p>

<p><strong>Here is the current code I used for 8-10</strong></p>

<pre><code>def show_magicians(names):
    """Print each magician name"""
    for name in names:
        msg = name.title()
        print(msg)

magician_names = ['sonic', 'tails', 'knuckles']
show_magicians(magician_names)

def make_great(list_magicians):
    """Add 'Great' to each name."""
    for magician_name in magician_names:
        for i in range(len(list_magicians)):
            list_magicians[i] += " the great!"

make_great(magician_names)
show_magicians(magician_names)
</code></pre>

<p>I don't know why but it just seems that I've been struggling through out this entire chapter of functions. Does anyone by any chance have any recommended tutorials to take a look at to help me understand functions better? Thank you for your time.</p>

<p>Let's look at your <code>make_great</code> function:</p>

<pre><code>def make_great(list_magicians):
    """Add 'Great' to each name."""
    for magician_name in magician_names:
        for i in range(len(list_magicians)):
            list_magicians[i] += " the great!"
</code></pre>

<p>What does this do?</p>

<p><code>for magician_name in magician_names:</code> Loops through <code>magician_names</code>.</p>

<p><code>for i in range(len(list_magicians)):</code> Loops through <code>list_magicians</code> by index.</p>

<p><code>list_magicians[i] += " the great!"</code> Adds <code>the great!</code> to the <code>i</code>th element of <code>list_magicians</code></p>

<p>What line of code isn't necessary?</p>

<p><code>for magician_name in magician_names:</code> Looping through this provides no use. Since its length is 3, that's why you get 3 <code>the great!</code>s added to each element. Remove that line of code and the function should work properly.</p>

python