0
0
Pythonprogramming~10 mins

Adding and removing list elements 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 add the number 5 to the list.

Python
numbers = [1, 2, 3]
numbers.[1](5)
print(numbers)
Drag options to blanks, or click blank then click option'
Aremove
Bappend
Cpop
Dinsert
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using remove instead of append will cause an error because 5 is not in the list.
Using pop removes an element instead of adding one.
2fill in blank
medium

Complete the code to remove the element 3 from the list.

Python
numbers = [1, 2, 3, 4]
numbers.[1](3)
print(numbers)
Drag options to blanks, or click blank then click option'
Aappend
Bpop
Cinsert
Dremove
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using pop without an index removes the last element, not the specified one.
Using append adds an element instead of removing.
3fill in blank
hard

Fix the error in the code to remove the last element from the list.

Python
items = ['a', 'b', 'c']
items.[1]()
print(items)
Drag options to blanks, or click blank then click option'
Apop
Bremove
Cappend
Dinsert
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using remove() without an argument causes an error.
Using append() adds an element instead of removing.
4fill in blank
hard

Fill both blanks to create a list of squares for numbers greater than 3.

Python
squares = [x[1]2 for x in range(1, 6) if x [2] 3]
print(squares)
Drag options to blanks, or click blank then click option'
A**
B>
C<
D+
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '+' instead of '**' will add numbers instead of squaring.
Using '<' instead of '>' will select wrong numbers.
5fill in blank
hard

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

Python
result = [1]: [2] for [3], v in data.items() if v > 0}
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Dvalue
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'value' instead of 'v' causes a NameError.
Not using .upper() keeps keys lowercase.