Trying to modify a list in Python, receiving "variable not defined" error

Joined
Dec 12, 2022
Messages
8
Reaction score
0
The assignment is "consider a company that creates 3D printed models of designs that users submit. Designs that need to be printed are stored in a list, and after being printed they're moved to a separate list."
Here is my code:
Python:
# Start with some designs that need to be printed
unprinted_designs = ['phone case', 'robot pendant', 'dodecahedron']
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()
    print(f"Printing model {current_design}")
    completed_models.append(current_design)

# Display all completed models
print("\nThe following models have been printed:")
for compeleted_model in completed_models:
    print(completed_model)

It's saying that at the end "completed_model" is not defined. Was it supposed to be? I thought that for a for loop you could just make up any variable for the first part.
Any help would be appreciated. Thanks in advance
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
The assignment is "consider a company that creates 3D printed models of designs that users submit. Designs that need to be printed are stored in a list, and after being printed they're moved to a separate list."
Here is my code:
Python:
# Start with some designs that need to be printed
unprinted_designs = ['phone case', 'robot pendant', 'dodecahedron']
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()
    print(f"Printing model {current_design}")
    completed_models.append(current_design)

# Display all completed models
print("\nThe following models have been printed:")
for compeleted_model in completed_models:
    print(completed_model)

It's saying that at the end "completed_model" is not defined. Was it supposed to be? I thought that for a for loop you could just make up any variable for the first part.
Any help would be appreciated. Thanks in advance
Yes, you're right, the error message is due to a typo in the for loop. Instead of using compeleted_model use completed_model

Python:
# Start with some designs that need to be printed
unprinted_designs = ['phone case', 'robot pendant', 'dodecahedron']
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()
    print(f"Printing model {current_design}")
    completed_models.append(current_design)

# Display all completed models
print("\nThe following models have been printed:")
for completed_model in completed_models:
    print(completed_model)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,367
Latest member
Monarch

Latest Threads

Top