0
0
Pythonprogramming~10 mins

List creation and representation 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 create a list named fruits with three items: 'apple', 'banana', and 'cherry'.

Python
fruits = [1]
Drag options to blanks, or click blank then click option'
A{'apple', 'banana', 'cherry'}
B('apple', 'banana', 'cherry')
C['apple', 'banana', 'cherry']
D'apple', 'banana', 'cherry'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using parentheses instead of square brackets creates a tuple, not a list.
Using curly braces creates a set, which is unordered.
Writing items without brackets creates a syntax error.
2fill in blank
medium

Complete the code to create an empty list named numbers.

Python
numbers = [1]
Drag options to blanks, or click blank then click option'
A[]
B()
C{}
D''
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using parentheses creates an empty tuple, not a list.
Using curly braces creates an empty dictionary, not a list.
Using empty quotes creates an empty string.
3fill in blank
hard

Fix the error in the code to correctly create a list named colors with 'red', 'green', and 'blue'.

Python
colors = [1]
Drag options to blanks, or click blank then click option'
A['red', 'green', 'blue']
B{'red', 'green', 'blue'}
C('red', 'green', 'blue')
D'red', 'green', 'blue'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using parentheses instead of square brackets.
Using curly braces which create a set.
Listing items without brackets causes syntax errors.
4fill in blank
hard

Fill both blanks to create a list of squares for numbers 1 to 5 using list comprehension.

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

Fill all three blanks to create a dictionary where keys are uppercase words and values are their lengths, but only for words longer than 4 letters.

Python
result = { [1]: [2] for word in words if len(word) [3] 4 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using word instead of word.upper() for keys.
Using word instead of len(word) for values.
Using <= or < instead of > in the condition.