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

Why won't task 2 pass?

Not sure why it won't check as correct.

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(dict):
    teacher_count = 0
    for teacher in dict:
        teacher_count +=1
    return teacher_count



def num_courses(dict):
    num_courses = 0
    for value in dict.values():
        num_courses += 1
    return num_courses

I've since changed the variable of num_courses to just courses so its different then my function name and it passed. The issue is it just refreshes back to challenge 2 and is now saying it doesn't work. Is this challenge bugged?

Eric M
Eric M
11,546 Points

I've had a lot of trouble with the python challenges being a little buggy (much moreso than Java or JavaScript) sometimes you have a working solution (I usually check in my local terminal) but the treehouse checker has cached a previous failed solution or something.

Sometimes I've had to log off, close all browser windows, and then come back in to the challenge.

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Kevin, your code basicaly does the same what you did for the first challenge. To pass the challenge you need to sum up every lengh of the "values" that belong to every key == teacher.

Every loop cycle will assign a list of courses to value. The number of the courses can vary, so in order to get a sum of all courses you will need ot add the length of every list with courses to num_courses.

def num_courses(dict):
    num_courses = 0
    for value in dict.values():
        num_courses += len(value)
    return num_courses

Does it make sense?