Challenge - 5 Problems
Set Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of set difference operation
What is the output of this Python code?
Python
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
result = a - b
print(result)Attempts:
2 left
๐ก Hint
Remember, set difference returns elements in the first set not in the second.
โ Incorrect
The difference a - b returns elements in a that are not in b, which are 1 and 2.
โ Predict Output
intermediate2:00remaining
Output of symmetric difference operation
What does this code print?
Python
x = {10, 20, 30}
y = {20, 40, 50}
print(x ^ y)Attempts:
2 left
๐ก Hint
Symmetric difference returns elements in either set but not both.
โ Incorrect
The symmetric difference excludes 20 because it is in both sets, leaving 10, 30, 40, and 50.
๐ง Conceptual
advanced1:30remaining
Understanding difference with empty set
What is the result of the difference operation when subtracting an empty set from a non-empty set?
Attempts:
2 left
๐ก Hint
Think about what elements are removed when subtracting nothing.
โ Incorrect
Subtracting an empty set removes no elements, so the original set remains unchanged.
โ Predict Output
advanced2:00remaining
Result of chained symmetric difference
What is the output of this code?
Python
a = {1, 2, 3}
b = {2, 3, 4}
c = {3, 4, 5}
result = a ^ b ^ c
print(result)Attempts:
2 left
๐ก Hint
Symmetric difference is associative; think step-by-step.
โ Incorrect
First a ^ b = {1, 4}, then {1, 4} ^ c = {1, 3, 5}.
๐ง Debug
expert2:00remaining
Identify the error in set difference code
Which option will cause an error when run?
Python
s1 = {1, 2, 3}
s2 = [2, 3, 4]
result = s1 - s2
print(result)Attempts:
2 left
๐ก Hint
Check the types used in the difference operation.
โ Incorrect
Subtracting a list from a set with '-' operator raises a TypeError.