Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to concatenate two lists.
Python
result = [1, 2, 3] [1] [4, 5, 6]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '*' instead of '+' causes an error or unexpected behavior.
Using '-' or '/' are not valid for lists.
โ Incorrect
The + operator joins two lists together.
2fill in blank
mediumComplete the code to repeat the list three times.
Python
result = [0, 1] [1] 3
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '+' concatenates lists but does not repeat.
Using '-' or '/' are not valid for lists.
โ Incorrect
The * operator repeats the list multiple times.
3fill in blank
hardFix the error in the code to correctly concatenate two lists.
Python
result = [1, 2, 3] [1] [4]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Trying to add a list and an integer directly causes an error.
Using '*' with a number on the right repeats the list, but here the right side is not a list.
โ Incorrect
To concatenate lists, both sides must be lists. Here, 4 is not a list, so use + with a list on the right side.
4fill in blank
hardFill both blanks to create a list of three repetitions of [7, 8] concatenated with [9].
Python
result = [7, 8] [1] 3 [2] [9]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '+' before '*' changes the order of operations.
Using '-' or '/' causes errors.
โ Incorrect
First, repeat the list [7, 8] three times using *, then concatenate the result with [9] using +.
5fill in blank
hardFill all three blanks to create a list with the uppercase letters repeated twice and concatenated with ['Z'].
Python
letters = ['a', 'b', 'c'] result = [[1] for l in letters] [2] 2 [3] ['Z']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
l.lower() instead of l.upper().Using '+' instead of '*' for repetition.
Using '*' instead of '+' for concatenation.
โ Incorrect
Use l.upper() to convert letters to uppercase, repeat the list twice with *, then concatenate with + ['Z'].