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

return total number

I keep getting error messages that i didn't get the right number for courses

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):
    number=len(teachers)
    return number

def num_courses(teachers):
    for teacher in teachers:
        courses=len(teachers)
        courses +=1
        return courses

1 Answer

Philip Schultz
Philip Schultz
11,437 Points

Hey Matt, You will want to make a variable that will keep count of all of the courses. Remember that this is a dictionary and you want to loop through the values, you can do that by using the .values() method. Take a look how I did the num_courses challenge and let me know if you have questions. I'll try to answer the best I can.

def num_courses(teachers):
    num_courses = 0
    for courses in teachers.values():
        num_courses += len(courses)
    return num_courses

i am still having 'try again' messages

Philip Schultz
Philip Schultz
11,437 Points

Hey Matt, I just copied and pasted my code above and it passed task 2 of 5...... that is the one you are having trouble with, right? If so, and it still isn't working, try to refresh your browser. If that still doesn't work then completely restart your browser. I was having very similar issues the other day and I wrote to treehouse support - here is how they responded.

"If you are using Internet Explorer or Safari, please switch to Google Chrome or Mozilla Firefox. If you're already using Chrome or Firefox and you are still experiencing this issue, please disable your plugins. You can do this temporarily by opening a new window up in Incognito Mode (Chrome) or Safe Mode (Firefox). If a Code Challenge works within one of those two disabled plugin windows then the problem is a plugin on your browser that you'll need to remove.

We may also recommend trying a different network to rule out any connection issues."