Challenge - 5 Problems
List Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
What is the output of this code?
Consider the following Python code. What will be printed?
Python
fruits = ['apple', 'banana', 'cherry', 'date'] print(len(fruits)) print('banana' in fruits) print('grape' in fruits)
Attempts:
2 left
๐ก Hint
Remember, len() counts all items in the list. The 'in' keyword checks if an item exists.
โ Incorrect
The list has 4 items, so len(fruits) is 4. 'banana' is in the list, so True. 'grape' is not, so False.
โ Predict Output
intermediate2:00remaining
What is the length of the list after modification?
What will be the output of the following code?
Python
numbers = [1, 2, 3, 4, 5] numbers.append(6) numbers.remove(2) print(len(numbers))
Attempts:
2 left
๐ก Hint
Appending adds one item, removing deletes one item.
โ Incorrect
Original list has 5 items. Append adds one (6), remove deletes one (2), so total remains 5.
โ Predict Output
advanced2:00remaining
What does this code print?
Analyze the code and select the correct output.
Python
items = ['pen', 'pencil', 'eraser', 'pen'] print(items.count('pen')) print('pen' in items) print(len(items))
Attempts:
2 left
๐ก Hint
count() returns how many times an item appears.
โ Incorrect
'pen' appears twice, so count is 2. 'pen' is in the list, so True. List length is 4.
โ Predict Output
advanced2:00remaining
What error does this code raise?
What error will this code produce when run?
Python
my_list = [10, 20, 30] print(my_list[3])
Attempts:
2 left
๐ก Hint
List indices start at 0 and go up to length-1.
โ Incorrect
Index 3 is out of range for a list of length 3, causing IndexError.
๐ง Conceptual
expert2:00remaining
How many items are in the resulting list?
What is the length of the list after this code runs?
Python
a = [1, 2] b = a b.append(3) print(len(a))
Attempts:
2 left
๐ก Hint
Remember that lists are mutable and variables can reference the same list.
โ Incorrect
Both 'a' and 'b' point to the same list. Appending via 'b' changes 'a' too, so length is 3.