0
0
Pythonprogramming~10 mins

Dictionary creation 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 an empty dictionary named my_dict.

Python
my_dict = [1]
Drag options to blanks, or click blank then click option'
A[]
B()
C{}
Dset()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets [] creates a list, not a dictionary.
Using parentheses () creates a tuple, not a dictionary.
2fill in blank
medium

Complete the code to create a dictionary person with keys 'name' and 'age'.

Python
person = [1]
Drag options to blanks, or click blank then click option'
A{'name': 'Alice', 'age': 30}
B"name=Alice, age=30"
C('name', 'Alice', 'age', 30)
D['name': 'Alice', 'age': 30]
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets with colons is invalid syntax.
Using tuples or strings instead of dictionary syntax.
3fill in blank
hard

Fix the error in the dictionary creation code.

Python
data = [1]
Drag options to blanks, or click blank then click option'
A{'x': 10, 'y': 20}
B{x: 10, y: 20}
C['x': 10, 'y': 20]
D{'x' = 10, 'y' = 20}
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using equal signs instead of colons.
Using square brackets instead of curly braces.
4fill in blank
hard

Fill both blanks to create a dictionary squares mapping numbers 1 to 3 to their squares.

Python
squares = { [1]: [2] for [1] in range(1, 4) }
Drag options to blanks, or click blank then click option'
Ax
Bx**2
Ci
Di*2
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using different variable names for key and loop variable.
Using multiplication by 2 instead of square.
5fill in blank
hard

Fill all three blanks to create a dictionary filtered with keys as uppercase words and values as their lengths, only for words longer than 3 letters.

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