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 trialBrian Wang
2,685 PointsHelp with the second code challenge..
why is my code not working?
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(a_set_of_topic):
a_list_of_courses = []
for course in COURSES:
if a_set_of_topic.intersection(COURSES[course]):
a_list_of_courses.append(course)
return a_list_of_courses
def covers_all(a_single_set):
a_list_of_courses = []
for course, topic in COURSES.items():
if a_single_set.intersection(COURSES[topic]):
a_list_of_courses.append(course)
return a_list_of_courses
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsThe Task 2 "Bummer" is coming from the code COURSES[topic]
. The key topic
is assigned by the for
loop to be list of topics covered by a course. It is a set. In the context of your code, you should use the set topic
directly.
Fixing this gets passed the Bummer, but yields the wrong results. Name, a course is being added to the a_list_of_courses
if there is any common topic between the sets. This is not sufficient. All of the topics in topic
have to be present in the course.
Hint: how would the length of the intersection compare to the length of topic
if all topics were covered?
Post back if you need more help. Good Luck!!!