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 trialSean Clayton
Courses Plus Student 1,029 PointsSomething wrong with courses code?
my function courses isn't returning what I want. Or, should I say, I think it should return the correct answer.
From my view - I have the correct function, I created an empty list and created a for loop which found the values and appended the list. Finally I returned the total number correctly(I think!)
Guidance would be appreciated
def num_teachers(teachers):
total_teachers = list(teachers.keys())
return(len(total_teachers))
def num_courses(teachers):
total_courses = (sum(map(len, teachers.values())))
return(total_courses)
def courses(teachers):
total_courses = []
for number in teachers.values():
total_courses.extend(number)
return total_courses
3 Answers
ursaminor
11,271 PointsDid you by any chance mix spaces and tabs? Or copy and paste? I think that can cause a problem sometimes.
Pedro Cabral
33,586 PointsAt the moment, the function returns a list of all the values of whatever dictionary is passed in, so assuming assuming you feed it with the challenge dictionary:
['jQuery Basics', 'Node.js Basics', 'Python Basics', 'Python Collections']
You say that it's not returning what you want, what were you expecting the output to be?
Sean Clayton
Courses Plus Student 1,029 PointsThe challenge reads as follows: "Great work! OK, you're doing great so I'll keep increasing the difficulty. For this step, make another new function named courses that will, again, take the dictionary of teachers and courses. courses, though, should return a single list of all of the available courses in the dictionary. No teachers, just course names!"
The code I've got doesn't work to pass although I get no guidance just a Try Again error
Sean Clayton
Courses Plus Student 1,029 PointsYeah, this is task 3
Pedro Cabral
33,586 PointsIs that task 3? Your code passes with me.
Pedro Cabral
33,586 PointsSean Clayton
Courses Plus Student 1,029 PointsI get this when I try and check! Something broken in the system maybe?
Pedro Cabral
33,586 PointsStrange, I can't help you any further. Maybe some one from staff will be able to help.
ursaminor
11,271 PointsAwesome! Glad that worked :)
Sean Clayton
Courses Plus Student 1,029 PointsSean Clayton
Courses Plus Student 1,029 PointsI didn’t paste it from anywhere, though was trying it in workspaces while trying it, but a re-write will be a good shout when I get home!
Sean Clayton
Courses Plus Student 1,029 PointsSean Clayton
Courses Plus Student 1,029 PointsI re-wrote everything and it sailed through. Frustrating mistake - thanks for your help!