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 Python Collections (2016, retired 2019) Dictionaries Teacher Stats

John Fu
John Fu
2,594 Points

Challenge task 2 of 5

I'm trying to work the second step of the challenge. I'm getting confused. I tried running my code through the repl(?) but I keep receiving File "<stdin>" line 2 syntax error: can't assign to function call. I'm confused on where my syntax error lies.

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(school):
    return len(school)

def num_courses(school):
    c = 0
    course_count = 0
    for course in school:
        course_count() = course_count + len(school.value(c))
        c = c+1
    return course_count

1 Answer

diogorferreira
diogorferreira
19,363 Points

That would be because you're calling course_count()

  • You can just replace it with course_count

Like this

course_count = course_count + len(school.value(c))

This is an example of a correct answer that you can try if you're really stuck, make sure you try before though

def num_courses(dictionary):
    course_count = 0
    for teacher, courses in dictionary.items():
        course_count += len(courses)
    return course_count