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 trialTerry Felder
1,738 PointsWHY?!?! do MY codes not work
my code never wants to work!! i have to look up other peoples code suggestions to use and answers to move on!! it work fine in my repl.it prints the list out everytime from the dictionary why is it not good enough for treehouse??
please excuse frustration but as you all know we put alot of time and thought into our codes so its very upsetting just seeing the Bummer: Try again! with every attempt.
p.s and for the most part there have been times were my code was perfect it didnt work i look online find someone with the same exact format just with one or two different variable names and it works just fine....like i said i wouldnt maybe be upset if i would get a HELPFUL!! message other than Bummer: Try again! ...that tells me treeehouse cant keep up with me..i dont get any error message other than that!! please please please help....
p.p.s to lazy to spell check right now. not stupid just typing fast lol ....
# 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.
# dic_school = {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
def num_teachers(school):
teacher = 0
for num_of_teach in school:
teacher += 1
return teacher
def num_courses(teachers):
return sum(len(v) for v in teachers.values())
def courses(teachers):
lis = []
for classes in teachers.values():
for x in classes:
new = lis.append(x)
return lis
2 Answers
Viraj Deshaval
4,874 PointsHi Terry, First of don't get frustrated because this happens to all and the way we should go about is to try and test our concepts what we learned using code challenges. If we don't get through we have a wonderful community out here to help you. I executed your code and it worked like a champ for me see what I did.
def num_teachers(school):
teacher = 0
for num_of_teach in school.keys():
teacher += 1
return teacher
def num_courses(teachers):
return sum(len(v) for v in teachers.values())
def courses(teachers):
lis = []
for classes in teachers.values():
for x in classes:
new = lis.append(x)
return lis
the only thing was missing is 'keys()' in the 'num_teachers' function.
for num_of_teach in school.keys():
Try now it should work. Treehouse is asking this challenge to test your knowledge and its great to solve this challenges you solved a lot. Try for other two parts as well. Good luck.
Cooper Runstein
11,850 PointsViraj nailed his response and he found the correct error, I'd just like to offer my two cents. This might sound kind of terrible, but you're always wrong when something goes wrong while programming. What I mean by that, is the errors that you make are due to the fact that you're a human, and you make mistakes. A computer doesn't make mistakes; a for loop will always run if done properly, but if you type it wrong, it won't. I know we all want to be right all the time, but by humbling yourself and realizing that the computer is always the right one saved me a lot of frustration. It made me slow down and realize that there were about 5 things that I consistently would do wrong, not intentionally, just as part of learning and being new at something. It really helps to never copy and paste code, and to only move on when you 100% understand not just the code, but the mistake you made and what you did wrong. Eventually you'll be a master at noticing your own mistakes, but it requires you taking the time to, as you put it, understand why the few variable name changes made a difference.
Also, I too get frustrated at the generic responses treehouse challenges give you, unfortunately they can't account for all the mistakes that can be made. It helps sometimes to write a few tests first and create your own feedback for yourself, not only is it a really good practice to learn if you want to be employed, but it helps you grow as a programmer a lot too.
Terry Felder
1,738 PointsCooper, when you put it like that your absolutely right i am a straight forward person so what you said wasn't terrible at all its fact...and your right i gotta stop getting mad at the computer, and start paying attention to my mistake patterns...
Terry Felder
1,738 PointsTerry Felder
1,738 PointsViraj Deshaval
WOW!!! thank you sooo much you jjust blew my mind...i got so caught up in the function i was doing i didnt bother to take a look at my other functions. i just took in all you said an learned a huge lesson!i get so caught up in the bits and forget to look at the whole picture thank you i will be sure to keep this in mind for future reference! thanks for the motivation.....ill just say i cant thank you enough lol
Viraj Deshaval
4,874 PointsViraj Deshaval
4,874 PointsIt's my pleasure. You can mark it as best answer so that others can even find it as useful. Cheers :)