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 trialHerman Vicens
12,540 PointsDon't know what is happening here
Getting the : Couldn't find num_teachers
error . The num_teachers def is present. Need help. thanks
# 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
matth89
17,826 PointsHey, 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
12,540 PointsThanks! I would have never find out on my own. Thank you!
matth89
17,826 PointsGlad to help!