I’m doing the python mega course on udemy, and I get an error
I get an error even though i did exactly what the instructor did. It is supposed to show all your todo items when you type “show” but it gives an error. Here’s the code:
new_todos = []
for item in todos:
new_item = item.strip('n')
new_todos.append(new_item)
case 'show' | 'display':
file = open('../todos.txt', 'r')
todos = file.readlines()
for index, item in enumerate(new_todos):
item = item.title()
row = f"{index + 1}-{item}"
print(row)
And here’s the error:
Traceback (most recent call last):
File “C:Python Programing – ArditPython Programs 2024app1pythonProjectfilesmain.py”, line 28, in
for index, item in enumerate(new_todos):
^^^^^^^^^
NameError: name ‘new_todos’ is not defined
It says that “new_todos” isnt defined, but looking at the code it is. Please help
Nathan Nuke is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2