Python Crash Course 8-15, Not Defined Error
<p>I'm reading the book 'Python Crash Course' by Eric Matthes and I seem to be having issues with exercise 8-15.</p>

<p>8-15 says: "Put the functions for the example print_models.py in a separate file called printing_functions.py. Write an import statement at the top of print_models.py, and modify the file to use the imported functions.</p>

<p><strong>Here is my code for the printing_functions.py module:</strong></p>

<pre><code>def print_models(unprinted_designs, completed_models):
    """Simulate printing each design, until none are left.
    Move each design to completed_models after printing."""
    while unprinted_designs:
        current_design = unprinted_designs.pop()

        # Simulate creating a 3D print from the design.
        print("Printing model: " + current_design)
        completed_models.append(current_design)

def show_completed_models(completed_models):
    """Show all the models that were printed."""
    print("\nThe following models have been printed:")
    for completed_model in completed_models:
        print(completed_model)

unprinted_designs = ['iphone case', 'robot pendant', 'dodecahedron']
completed_models = []
print_models(unprinted_designs, completed_models)
show_completed_models(completed_models)
</code></pre>

<p><strong>Here is my code for exercise 8-15</strong></p>

<pre><code>import printing_functions as pf

pf.print_models(unprinted_designs, completed_models)
pf.show_completed_models(completed_models)

unprinted_designs = ['iphone case', 'robot pendant', 'dodecahedron']
completed_models = []
print_models(unprinted_designs, completed_models)
show_completed_models(completed_models)
</code></pre>

<p>When I run this code, I'm able to receive the same output as in the module. However I also receive and error at the bottom stating that 'unprinted_designs' is not defined. But I clearly have this variable defined near the bottom of my code as a list so I do not understand why I am getting this error. </p>

<p>Does anyone have any ideas as to what I may be doing wrong? Any feedback would be greatly appreciated. Thank you for your time.</p>

<p>You've mostly done the correct thing, but variables need to be assigned before you can use them. </p>

<p>Also, since you've separated / moved the functions to a module, you have to use those imported ones while the variables remain in this module  </p>

<pre><code>import printing_functions as pf

unprinted_designs = ['iphone case', 'robot pendant', 'dodecahedron']
completed_models = []

pf.print_models(unprinted_designs, completed_models)
pf.show_completed_models(completed_models)
</code></pre>

<p>Then, remove the unnecessary lines at the end of the other module. Only the function definitions should be there </p>

python