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 trialT.j. Twilley
2,317 PointsAt a road block with the Teacher Stat's challenge
I'm having problems with the for loop. Could someone point out what I'm doing with the classes variable?
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
def most_classes (teacher_dict):
max_count = 0
teacher = ""
for items in teacher_dict:
classes = len(teacher_dict[tacher])
if classes > max_count:
teacher = items
max_count = classes
return teacher
1 Answer
Kenneth Love
Treehouse Guest TeacherI see a few problems. Let's look at them:
def most_classes (teacher_dict):
max_count = 0 # good!
teacher = "" # good!
for items in teacher_dict: # here, `items` is a single teacher
classes = len(teacher_dict[tacher]) # where did `tacher` come from? Should be using `items`
if classes > max_count: # good
teacher = items # not sure what you're doing here
max_count = classes # good
return teacher # this needs to be indented so it's inside of the function
Hopefully that helps you over the roadblock.
T.j. Twilley
2,317 PointsT.j. Twilley
2,317 PointsThanks!!! I used the "teacher=items", because I wanted to make sure that items was assigned to teacher. Also I'm still having problems because sometimes it passes and other times it fails. Why is that?