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

it works in my terminal but yet I get "Bummer! Couldn't find `most_courses`" common treehouse!!!!

Idk even what to say here besides the fact that my method exist and that there is no reason I should be getting the feedback "Bummer! Couldn't find most_courses" I have this method at the top of my code and it works with me running python 3.6.0.

I feel like this is a glitch in the team treehouse compiler any suggestions people?

Thank you even if you tried.

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 most_courses(dict_o):
    current_count = 0
    max_c = 0
    i = 0
    max_name = ''
    for classes in dict_o.values():
        for a_class in classes:
            current_count+=1
            if current_count > max_c:
                max_name = list(teacher_classes.keys())[i]
            i+=1
        i=0
        current_count = 0
    return max_name

def num_teachers(dict_o):
    return len(dict_o)

def num_courses(dict_o):
    i = 0
    for classes in dict_o.values():
        i+=len(classes)
    return i

def courses(dict_o):
    list_o = []
    i = 1
    for classes in dict_o.values():
        for a_class in classes:
            list_o.append((a_class))
    return list_o
Cheo R
Cheo R
37,150 Points

Try moving that method in the order they're given (I forget, is that the last challenge?).

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,736 Points

I think it's a misleading error message. The method exists but there are problems that are making it break. I ran your code and I added a line that tries passing in the sample data the way I expect the challenge will be testing your code. My extra lines look like this:

test_courses = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'], 'Kenneth Love': ['Python Basics', 'Python Collections']}
print(most_courses(test_courses))

And when I run it in the terminal I get this:

Desktop: python teachers.py
Traceback (most recent call last):
  File "teachers.py", line 44, in <module>
    print(most_courses(test_courses))
  File "teachers.py", line 37, in most_courses
    max_name = list(teacher_classes.keys())[i]
NameError: name 'teacher_classes' is not defined

I guess what I'm trying to say is that when you submit your code, it's going to take it and run it with some test cases that are hidden from us but it expects a certain output, and if there's a problems with your code it will throw an error. Some of the other Treehouse challenges let you see the actual error messages to debug but not this one.