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 trialNader Alharbi
2,253 PointsMy code gives the correct results, but i still receive error message.
Hello there,
I wrote the code for this task and tested it in my python interpreter and it works perfectly, but when i tried to submit my answer it gives me error for some reason which is kinda weird.
Also, if there is a better way other than comparison to an empty set, i would to learn it. Thank you.
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_all(title):
list_courses = []
for course_dictionary in COURSES:
if title - COURSES[course_dictionary] == set():
list_courses.append(course_dictionary)
return list_courses
1 Answer
Oszkár Fehér
Treehouse Project ReviewerHi Nader Alharbi. You are very close and you are right, in the python interpreter, it passes but not in the challenge, the reason is that because the challenge asking overlap
in other words intersection()
or &
. The method what you used is difference()
or -
. Of course, you don't need the comparison as well, == set()
. Also, double check the naming of the covers
function, only in the second half of the challenge you need to name it like covers_all
.
I hope this will help you out in the first half, the second part it's not so different from the first just read carefully the instructions. Happy coding!
Nader Alharbi
2,253 PointsNader Alharbi
2,253 PointsSorry if i was not clear on this, I already passed part one with intersection and this code is for part 2 which i am stuck on.
Oszkár Fehér
Treehouse Project ReviewerOszkár Fehér
Treehouse Project ReviewerThe second part is not so different from the first, just a different method should be used. On the second quiz, you need to invert what is in the
if
statement, you looking forsubset
. Also, don't forget to keep the first function, thecovers
. I hope this will help you to figure out. Happy coding.Nader Alharbi
2,253 PointsNader Alharbi
2,253 PointsHahaha, you were right. My function was correct. All i had to do is just add the function from part 1 (covers).
I passed the question, but i still don't understand one thing, how can i remove the checking for empty set in my if condition? i want to be coding in the best way not just pass questions with unnecessary codes
Oszkár Fehér
Treehouse Project ReviewerOszkár Fehér
Treehouse Project ReviewerYou mean
if title - COURSES[course_dictionary] == set(): <--- this set() part?
My solution was this
if COURSES[course_dictionary] >= title: