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 trialBruce Caraway
5,961 PointsTask 1 works fine until I start working on Task 2. The problem is not in Task 1 and I can't get any feedback on Task2.
How do I get the grader to look at my "new" Task 2 code?
# 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(teachers):
max_count = 0
max_teacher = ''
teacher_class_count = {}
for key in teachers:
teacher_count = 0
if key in teacher_class_count:
teacher_count = teacher_class_count[key]
teacher_class_count[key] = teacher_count
if teacher_class_count[key] > max_count:
max_count = teacher_class_count[key]
max_teacher = key
else:
teacher_class_count[key] = 1
if max_teacher =='':
max_teacher = key
max_count = 1
return max_teacher
def num_teachers(teachers):
teacher_count = 0
teachers_counted = []
for key in teachers:
if key not in teachers_counted:
teachers_counted.append(key)
teacher_count += 1
return teacher_count
2 Answers
Keerthi Suria Kumar Arumugam
4,585 PointsThere is a small flaw in your algorithm for task 1. If you look closely, you can see that the first "if" block inside your for loop is never executed. I have modified your algorithm slightly in the code below. Your code for the second task looks clean though. Check it out.
# 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(teachers):
print(teachers)
max_count = 0
max_teacher = ''
for key in teachers:
if max_teacher == '' or max_count < len(teachers[key]):
max_teacher = key
max_count = len(teachers[key])
return max_teacher
def num_teachers(teachers):
teacher_count = 0
teachers_counted = []
for key in teachers:
if key not in teachers_counted:
teachers_counted.append(key)
teacher_count += 1
return teacher_count
Bruce Caraway
5,961 PointsAh, yes - thanks Keerthi!