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 trialAnthony Lopez
963 PointsReturning the total number of courses for all teachers question!
Hey guys!
I'm trying to figure out why my function def num_courses(sing_arg) isn't working. When I type it out in my desktop application I get the correct number of classes, but the challenge is not accepting my answer in team tree house. I know it can be very particular.
Am I missing something? Thanks!
# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Each key will be a Teacher and the value will be a list of courses.
#
# Your code goes below here.
def num_teachers(sing_arg):
return len(sing_arg)
def num_courses(sing_arg):
value = 0
for courses in sing_arg.values():
for answer in courses:
if answer in courses:
value += 1
return value
Cooper Runstein
11,850 PointsYour answer passed when I copied and pasted it in, I'm not sure why it isn't passing.
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsThe originally posted code does not pass due to an error:
line 16
if answer in courses:
^
TabError: inconsistent use of tabs and spaces in indentation
clickpass
23,992 Pointsdef num_teachers(sing_arg):
return len(sing_arg)
def num_courses(sing_arg):
value = 0
for courses in sing_arg.values():
value += len(courses)
return value
Maybe I missed a typo or something. This code passes.
clickpass
23,992 Pointsclickpass
23,992 PointsThe second loop isn't necessary because you can get the length of the courses with len.