Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Bethany Watson
Bethany Watson
2,618 Points

Traceback: Name Error

I am getting this error. I researched the meaning of this and still not understanding what is wrong with line 20.

treehouse:~/workspace$ python linear_search.py                                                                 
Traceback (most recent call last):                                                                             
  File "linear_search.py", line 20, in <module>                                                                
    verify(result)                                                                                             
NameError: name 'verify' is not defined 

def linear_search(list, target):
    """
    Return the index position of the target if found, else returns None
    """

    for i in range(0, len(list)):
        if list[i] == target:
           return i
    return None

def verify(index):
    if index is not None:
        print("Target found at index: ", index)
    else:
        print("Target not found in list")

numbers = [1,2,3,4,5,6,7,8,9,10]

result = linear_search(numbers, 12)
verify(result)

Could you format your code using markdown? Hard to tell what is going on otherwise.

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,731 Points

Your code ran perfectly for me. There aren't any syntax or scoping errors.

I advise you save into another filename and try it again.

Here are my results below (with your unmodified code).

Keep up the good work!

treehouse:~/workspace$ ls                                                                              
linear_search.py  myproject                                                                            
treehouse:~/workspace$ python linear_search.py                                                         
Target not found in list