Challenge - 5 Problems
List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediateWhat is the output of this list operation?
Look at this Python code that uses a list. What will it print?
Python
fruits = ['apple', 'banana', 'cherry'] fruits.append('date') print(fruits)
Attempts:
2 left
๐ก Hint
Remember, append adds an item to the end of the list.
โ Incorrect
The append method adds the new item 'date' to the end of the list, so the list now has four items.
๐ง Conceptual
intermediateWhy use lists instead of separate variables?
Why is it better to use a list to store multiple values instead of separate variables like a1, a2, a3?
Attempts:
2 left
๐ก Hint
Think about how you would handle many items in a program.
โ Incorrect
Lists group many items together so you can manage them easily, like looping or changing items, instead of handling many separate variables.
โ Predict Output
advancedWhat is the output after modifying a list?
What will this code print?
Python
numbers = [1, 2, 3, 4] numbers[1] = 10 print(numbers)
Attempts:
2 left
๐ก Hint
Remember, lists can change items by index.
โ Incorrect
The code changes the second item (index 1) from 2 to 10, so the list becomes [1, 10, 3, 4].
โ Predict Output
advancedWhat error does this code raise?
What error will this code cause?
Python
my_list = [1, 2, 3] print(my_list[5])
Attempts:
2 left
๐ก Hint
Think about what happens if you ask for an item beyond the list length.
โ Incorrect
Accessing an index that does not exist in the list raises an IndexError.
๐ง Conceptual
expertWhy are lists useful for dynamic data?
Imagine you are making a shopping list app. Why is a list a good choice to store the items?
Attempts:
2 left
๐ก Hint
Think about how your shopping list changes over time.
โ Incorrect
Lists let you add or remove items easily, which fits well with changing shopping lists.
