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 trialThor-Erik Stoevland
9,553 Points"Bummer! Didn't get the right number of courses!" I can't see why my code isn't accepted?
Can someone see why my code doesnt work? As far as I know this shoul've been accepted.
def num_teachers(name): teachers = {} for i in name.keys(): return len(name.keys()) break
def num_courses(name): total_list = [] for i in teachers.values(): total_list.extend(i) total = len(total_list) print(total)
teachers = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'], 'Kenneth Love': ['Python Basics', 'Python Collections']}
num_courses(teachers)
# 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(name):
teachers = {}
for i in name.keys():
return len(name.keys())
break
def num_courses(name):
total_list = []
for i in teachers.values():
total_list.extend(i)
total = len(total_list)
return total
teachers = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
'Kenneth Love': ['Python Basics', 'Python Collections']}
num_courses(teachers)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! Your logic and syntax are spot on, but you're doing something that the challenge is not taking into account. You're creating a variable with a dictionary named teachers
in the global scope and then running the function yourself. While this is great for testing, you should be aware that Treehouse will be running your code and that this global variable will not be applicable. They are going to call your function and pass in a dictionary. You've elected to name the parameter name
. You are currently returning the value of the dictionary you made instead of the dictionary they are sending, and we have no idea what that dictionary looks like
So where you wrote this:
for i in teachers.values():
You should have:
for i in name.values():
Hope this helps!
Thor-Erik Stoevland
9,553 PointsThor-Erik Stoevland
9,553 PointsHello Jennifer!
Thank you very much. When I think about it, I'va had simillar issues before. I'll be more consistant from now on.
Yes it helped, thank you very much!