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 trialGavin Meisels
1,559 PointsDictionaries teachers.py couses
I need help it says task one is no longer passing in the forth question. this is my code.
def most_classes(teachers):
counts = []
max_classes = 0
for key in teachers:
counts.append(len(teachers[key]))
for value in counts:
if value > max_classes:
max_classes = value
for key in teachers:
if max_classes == len(teachers[key]):
return key
def num_teachers(teach_dict):
teach_count = 0
for name in teach_dict:
teach_count += 1
return teach_count
def stats(teachers):
total_stats = []
for teacher in teachers:
total_stats.append( [teacher, len(teachers[teacher])] )
return total_stats
def courses(teachers):
course = []
return course
1 Answer
Kenneth Love
Treehouse Guest TeacherWhen I ran your code, I got an indentation error. Python needs your indentation to match from one thing to the next. Notice how your most_classes
function has lots of indentation and the rest don't? Make 'em all match.
Gavin Meisels
1,559 Pointsdef most_classes(teachers):
counts = []
max_classes = 0
for key in teachers:
counts.append(len(teachers[key]))
for value in counts:
if value > max_classes:
max_classes = value
for key in teachers:
if max_classes == len(teachers[key]):
return key
def num_teachers(teach_dict):
teach_count = 0
for name in teach_dict:
teach_count += 1
return teach_count
def stats(teachers):
total_stats = []
for teacher in teachers:
total_stats.append( [teacher, len(teachers[teacher])] )
return total_stats
def courses(teachers):
course = []
for list_of_classes in teachers_dict.values():
all_courses.extend(teachers_dict.values())
return course
now it says: Bummer! Where's courses()
?
Whats wrong with this code?
Kenneth Love
Treehouse Guest TeacherGavin Meisels Look at courses
. You have a variable named course
and then your for
loop extends a variable named all_courses
. You're also looping through teachers_dict
when the passed-in argument is teachers
.
I'll update the CC to give back that error
Gavin Meisels
1,559 Pointsdef courses(teachers): course = [] for list_of_classes in teachers_dict.values(): courses.extend(teachers_dict.values()) return course
Kenneth Love what did i do wrong here
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherEdited for markdown.