Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a list of fruits.
Python
fruits = [[1]] Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Forgetting commas between items
Using spaces instead of commas
Using plus signs to join items
โ Incorrect
Lists hold multiple items separated by commas inside square brackets.
2fill in blank
mediumComplete the code to access the first item in the list.
Python
first_fruit = fruits[[1]] Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using 1 instead of 0 for the first item
Using negative indexes without understanding
โ Incorrect
List indexes start at 0, so the first item is at index 0.
3fill in blank
hardFix the error in the code to add an item to the list.
Python
fruits.[1]('orange')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using 'add' which is not a list method
Using 'extend' which expects an iterable
Using 'insert' without specifying position
โ Incorrect
The append method adds a single item to the end of a list.
4fill in blank
hardFill 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]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using multiplication instead of power
Using less than instead of greater than
โ Incorrect
Use ** to square numbers and > to filter numbers greater than 3.
5fill in blank
hardFill all three blanks to create a dictionary of uppercase words with their lengths if length is more than 4.
Python
result = [1]: [2] for word in words if len(word) [3] 4}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using word instead of word.upper() for keys
Using < instead of > for filtering
Using word instead of len(word) for values
โ Incorrect
The dictionary keys are uppercase words, values are their lengths, filtered by length greater than 4.