0
0
Pythonprogramming~10 mins

List mutability in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to change the first item of the list to 10.

Python
numbers = [1, 2, 3]
numbers[0] = [1]
print(numbers)
Drag options to blanks, or click blank then click option'
Anumbers[1]
B0
C'10'
D10
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using quotes around 10 makes it a string, not an integer.
Trying to assign a value to numbers instead of numbers[0].
2fill in blank
medium

Complete the code to add the number 4 at the end of the list.

Python
numbers = [1, 2, 3]
numbers.[1](4)
print(numbers)
Drag options to blanks, or click blank then click option'
Ainsert
Bappend
Cextend
Dadd
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using insert without specifying the index.
Using extend which expects an iterable, not a single item.
3fill in blank
hard

Fix the error in the code to change the second item to 20.

Python
numbers = [5, 6, 7]
numbers[[1]] = 20
print(numbers)
Drag options to blanks, or click blank then click option'
A1
B2
C0
D3
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using index 2 which is the third item.
Using index 3 which is out of range.
4fill in blank
hard

Fill both blanks to create a new list with squares of numbers greater than 2.

Python
numbers = [1, 2, 3, 4, 5]
squares = [x[1]2 for x in numbers if x [2] 2]
print(squares)
Drag options to blanks, or click blank then click option'
A**
B%
C>
D+
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using % which is modulo, not power.
Using + which adds numbers instead of squaring.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 3.

Python
numbers = {'a': 1, 'b': 4, 'c': 5}
result = [1]: [2] for [3], v in numbers.items() if v > 3}
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Dv.upper()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using v.upper() which is invalid because values are integers.
Using k instead of k.upper() for keys.