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 trialjohn larson
16,594 PointsNow it's just getting bizarre...challenge is telling me it got output that I DID NOT PUT!!!
Bummer! Didn't get the expected output. Got ['Dave McFarland', 1, 'Kenneth Love', 2, 'Pasan Premaratne', 4, 'Jason Seifer', 7, 'Andrew Chalkley', 4].
- you can see in my code I only have jason and kenneth, not the others
teachers_dict = {
'Jason Seifer': [
'Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
'Kenneth Love': [
'Python Basics', 'Python Collections']
}
def stats(teachers_dict):
name_num = []
for teacher in teachers_dict:
name_num.append(teacher)
name_num.append(len(teachers_dict[teacher]))
print(name_num)
return name_num
stats(teachers_dict)
Jennifer Nordell
Treehouse TeacherAssuming we're looking at the challenge linked at the top here, my best suggestion is to carefully read the instructions for the challenge again. It explicitly says that the function itself is to be named most_classes
. Also, the function (according to the instructions) is supposed to return the teacher that has the most classes. Currently, you're returning an array containing all teachers and how many classes they teach.
Hope this helps!
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! Here's the thing. Treehouse is going to call the function and send in their own data for the teacher_dict. It could be absolutely anything. Your code needs to work for whatever Treehouse sends in. The teachers_dict in the comments is merely an example. So while your definition for teachers_dict
only has those 2 teachers, this is obviously not true for the data set they're sending into your function.
Note: this is true for many challenges here on Treehouse.
Hope this helps!
john larson
16,594 PointsOk, I get it...thanks Jennifer.
john larson
16,594 PointsI must have posted that code under the wrong question, sorry. This is what the challenge said to do:
- return a list of lists containing all teachers and how many classes they teach.
john larson
16,594 Pointsjohn larson
16,594 PointsIn that case, this code seems to work perfectly in my editor. Do you see anything wrong with this code?