Challenge - 5 Problems
Membership Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Check membership in a list
What is the output of this code?
Python
fruits = ['apple', 'banana', 'cherry'] result = 'banana' in fruits print(result)
Attempts:
2 left
💡 Hint
Remember, 'in' checks if an item exists inside a list.
✗ Incorrect
The string 'banana' is inside the list fruits, so 'banana' in fruits returns True.
❓ Predict Output
intermediate2:00remaining
Check membership in a string
What is the output of this code?
Python
text = 'hello world' result = 'z' not in text print(result)
Attempts:
2 left
💡 Hint
The 'not in' operator returns True if the item is not found.
✗ Incorrect
The character 'z' is not in the string 'hello world', so 'z' not in text returns True.
❓ Predict Output
advanced2:00remaining
Membership check with dictionary keys
What is the output of this code?
Python
data = {'a': 1, 'b': 2, 'c': 3}
result = 'b' in data
print(result)Attempts:
2 left
💡 Hint
Membership in a dictionary checks keys, not values.
✗ Incorrect
The key 'b' exists in the dictionary data, so 'b' in data returns True.
❓ Predict Output
advanced2:00remaining
Membership check with a tuple
What is the output of this code?
Python
t = (10, 20, 30, 40) result = 25 not in t print(result)
Attempts:
2 left
💡 Hint
The 'not in' operator returns True if the item is not found in the tuple.
✗ Incorrect
The number 25 is not in the tuple t, so 25 not in t returns True.
🧠 Conceptual
expert3:00remaining
Understanding membership with nested lists
Given the code below, what is the output?
Python
nested = [[1, 2], [3, 4], [5, 6]] result = [3, 4] in nested print(result)
Attempts:
2 left
💡 Hint
Membership checks for the exact item in the list, including nested lists.
✗ Incorrect
The list [3, 4] is an element inside the nested list, so '[3, 4] in nested' returns True.