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 trialDaniel Adari
3,577 PointsTreehouse doesn't accept my code - already tested on my PC
I have tested the code on my pc (in pycharm) and it returned the right values. for some reason, Treehouse won't accept my code. Is it a bug? is my code incorrect?
COURSES = {
"Python Basics": {"Python", "functions", "variables",
"booleans", "integers", "floats",
"arrays", "strings", "exceptions",
"conditions", "input", "loops"},
"Java Basics": {"Java", "strings", "variables",
"input", "exceptions", "integers",
"booleans", "loops"},
"PHP Basics": {"PHP", "variables", "conditions",
"integers", "floats", "strings",
"booleans", "HTML"},
"Ruby Basics": {"Ruby", "strings", "floats",
"integers", "conditions",
"functions", "input"}
}
def covers(topic):
return_list = []
for x in COURSES:
value = COURSES[x]
intersect = value.intersection(topic)
if len(intersect) >= 1:
return_list.append(x)
return return_list
def covers_all(topic):
return_list = []
for x in COURSES:
value = COURSES[x]
intersect = value.intersection(topic)
if len(intersect) >= len(topic):
return_list.append(x)
return return_list
1 Answer
Louise St. Germain
19,424 PointsHi Daniel,
You're very close! Your code has a tiny minor bug, which is that the return statement on the very last line is indented one level too far, so it returns (and therefore exits the for loop) after the first iteration. If you unindent that line by a level (so that it's at the same level as the for... statement, not the if... statement), it will run through the for loop for all items in the dictionary, and only return at the very end.
That should make it all work! Hope this helps!
Daniel Adari
3,577 PointsDaniel Adari
3,577 PointsWhat a dumb mistake XD Thanks!