0
0
Pythonprogramming~10 mins

Why structured data formats are used in Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

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

Python
person = {'name': 'Alice', 'age': [1]
Drag options to blanks, or click blank then click option'
A30
B'30'
Cage
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number in quotes making it a string instead of an integer.
2fill in blank
medium

Complete the code to convert a dictionary to a JSON string.

Python
import json
person = {'name': 'Bob', 'age': 25}
json_str = json.[1](person)
Drag options to blanks, or click blank then click option'
Adumps
Bloads
Cdump
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using json.loads() which is for parsing JSON strings.
3fill in blank
hard

Fix the error in the code to parse a JSON string into a Python dictionary.

Python
import json
json_str = '{"city": "Paris", "population": 2148000}'
data = json.[1](json_str)
Drag options to blanks, or click blank then click option'
Adump
Bdumps
Cload
Dloads
Attempts:
3 left
💡 Hint
Common Mistakes
Using json.load() which reads from a file, not a string.
4fill in blank
hard

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

Python
squares = {x: x[1]2 for x in range(1, 6) if x [2] 3}
Drag options to blanks, or click blank then click option'
A**
B%
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using % which is modulo, not exponentiation.
Using < instead of >.
5fill in blank
hard

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

Python
filtered = [1]: [2] for k, v in data.items() if v [3] 10}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of uppercase.
Using < instead of >.