0
0
Pythonprogramming~20 mins

Why lists are used in Python - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What 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)
A['date', 'apple', 'banana', 'cherry']
B['apple', 'banana', 'cherry']
C['apple', 'banana', 'cherry', 'date']
DError: append is not a list method
Attempts:
2 left
๐Ÿ’ก Hint
Remember, append adds an item to the end of the list.
๐Ÿง  Conceptual
intermediate
2:00remaining
Why 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?
ALists make the program run faster than separate variables.
BLists prevent any changes to the stored items.
CLists automatically sort the items for you.
DLists let you store many items in one place and easily loop through them.
Attempts:
2 left
๐Ÿ’ก Hint
Think about how you would handle many items in a program.
โ“ Predict Output
advanced
2:00remaining
What is the output after modifying a list?
What will this code print?
Python
numbers = [1, 2, 3, 4]
numbers[1] = 10
print(numbers)
A[1, 10, 3, 4]
B[10, 2, 3, 4]
C[1, 2, 3, 4]
DError: lists do not support item assignment
Attempts:
2 left
๐Ÿ’ก Hint
Remember, lists can change items by index.
โ“ Predict Output
advanced
2:00remaining
What error does this code raise?
What error will this code cause?
Python
my_list = [1, 2, 3]
print(my_list[5])
ATypeError
BIndexError
CKeyError
DSyntaxError
Attempts:
2 left
๐Ÿ’ก Hint
Think about what happens if you ask for an item beyond the list length.
๐Ÿง  Conceptual
expert
3:00remaining
Why 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?
ABecause lists can grow or shrink as items are added or removed.
BBecause lists automatically save data to a file.
CBecause lists prevent duplicate items from being added.
DBecause lists can only store numbers.
Attempts:
2 left
๐Ÿ’ก Hint
Think about how your shopping list changes over time.