Python Python Collections (2016, retired 2019) Dictionaries Teacher Stats

Herman Vicens
Herman Vicens
12,540 Points

Don't know what is happening here

Getting the : Couldn't find num_teachers error . The num_teachers def is present. Need help. thanks

teachers.py
# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Each key will be a Teacher and the value will be a list of courses.
#
# Your code goes below here.

def num_teachers(teachers):
    for key in teachers.items():
        counter = counter + 1
    return counter

2 Answers

Matt Hanson
MOD
Matt Hanson
Treehouse Moderator 17,671 Points

Hey, Herman. This error is indeed misleading. I ran your code in a python shell, and it gave me the real error: UnboundLocalError: local variable 'counter' referenced before assignment.

When you do counter = counter + 1 you're telling the program to look for an already existing variable called counter, add one to it, and then make that the value of counter. If you initialize the counter variable outside of your loop first, your code will pass this step. Hope this helps! Let me know if you have questions.

Herman Vicens
Herman Vicens
12,540 Points

Thanks! I would have never find out on my own. Thank you!