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 trialOmar G.
3,620 PointsThe num_teachers function should return an integer for how many teachers are in the dict
Maybe I am misunderstanding the question but in this challenge, it wants us to return how many teachers are in the dictionary. Each teacher is a key so it wants us to return how many keys are in the dictionary as a number(int). So I wrote this code which does that.
this is my code:
def num_teachers(teachers):
print (len(teachers.keys()))
This using the sample list it printed 2 teachers and I added a few more teachers (as keys) and courses just to check and returned everything properly. But it says the number of teachers is wrong. Am I understanding the challenge incorrectly? Any hints to point me in the right direction would be appreciated.
1 Answer
andren
28,558 PointsThe challenge asks you to return the number of teachers, you are printing the number of teachers. The return
keyword and print
function might look more or less identical when used in the REPL (due to returned values being printed out automatically) but they actually do very different things. Simply put return
passes the value back to the code that called the function, while print
outputs the value to the console.
If you return
the length like this:
def num_teachers(teachers):
return len(teachers.keys())
Then your code will pass.
Edit: Added a simple explanation about what return
and print
does.
Omar G.
3,620 PointsOmar G.
3,620 PointsThank you so much. I can't believe I didn't notice that. Thank you so much!