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 trialCody Selman
7,643 PointsSet Math Challenge 1 - Not Sure What's Wrong With My Answer
I keep getting this error when checking my answer:
"Bummer: Didn't get the right output from covers."
My covers function seems to satisfy every test I throw at it. Here is my covers function:
def covers(topics_set):
course_list = []
for course in COURSES:
if topics_set.issubset(COURSES[course]):
course_list.append(course)
return course_list
Is there something wrong with my function that I'm not seeing? Any help would be appreciated.
Best regards,
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(topics_set):
course_list = []
for course in COURSES:
if topics_set.issubset(COURSES[course]):
course_list.append(course)
return course_list
KRIS NIKOLAISEN
54,972 PointsI compared your code to one that passed the challenge and received two different outputs
def covers(topics_set):
course_list = []
for course in COURSES:
if topics_set.issubset(COURSES[course]):
course_list.append(course)
return course_list
def covers2(topics):
common_list=[]
for subject,course in COURSES.items():
common_subject=topics.intersection(course)
if len(common_subject)>0:
common_list.append(subject)
return common_list
print(covers({"strings","floats"}))
print(covers2({"strings","floats"}))
results:
['Python Basics', 'PHP Basics', 'Ruby Basics']
['Python Basics', 'Java Basics', 'PHP Basics', 'Ruby Basics']
Dave StSomeWhere
19,870 PointsVery interesting Kris, changing it from subset
to intersection
does pass the challenge. For print(covers({"strings","floats"}))
the result includes Java Basics which doesn't have floats. Something is fishy
Here's a prior answer that might explain - Another Answer - I guess reading it as overlap means if any of set 1 are in set 2 and I did use intersection when I did this challenge.
1 Answer
Cody Selman
7,643 PointsOkay, I understand what the issue was. I had just misunderstood the question. The intention was for the function to return any courses that have any of the given topics, rather than having all of the given topics. Changing issubset to intersection made my code pass the challenge.
It's times like these that I wish TreeHouse had a more detailed error message for why your code fails a challenge. CodeWars has a really good way of handling these code challenges, for example.
Thank you everyone! This was the first time I ever had to just give up on a code challenge and move on so I'm really happy to be able to revisit it and solve the challenge.
I think you replied as a comment, Kris. Feel free to reply as an answer here so I can give you the Best Answer and close this thread.
Best regards,
Dave StSomeWhere
19,870 PointsDave StSomeWhere
19,870 PointsYour code also fails the challenge checker for me with the same error (some times restarting the challenge and/or your browser works, I did try a restart, didn't restart my browser). The code does appear to work locally for me and I tested 5 or 6 different test cases. Sure seems like the challenge checker is messing up. You might want to send a message to support, or maybe a mod will see this and help you out.