0
0
Intro to Computingfundamentals~10 mins

Dictionaries and key-value pairs in Intro to Computing - 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 dictionary with a key 'name' and value 'Alice'.

Intro to Computing
person = [1]
Drag options to blanks, or click blank then click option'
A{'name': 'Alice'}
B['name', 'Alice']
C('name', 'Alice')
D'name': 'Alice'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] creates a list, not a dictionary.
Using parentheses () creates a tuple, not a dictionary.
Writing key-value without braces is invalid syntax.
2fill in blank
medium

Complete the code to access the value of the key 'age' from the dictionary.

Intro to Computing
age = person[1]
Drag options to blanks, or click blank then click option'
A.age
B(age)
C['age']
D{'age'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses () tries to call a function, which is wrong here.
Using dot notation works for objects but not dictionaries.
Using curly braces {} is for creating dictionaries, not accessing values.
3fill in blank
hard

Fix the error in the code to add a new key 'city' with value 'Paris' to the dictionary.

Intro to Computing
person[1] = 'Paris'
Drag options to blanks, or click blank then click option'
A.city
B['city']
C(city)
D{city}
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation tries to access an attribute, which dictionaries don't support.
Using parentheses () or curly braces {} is invalid syntax here.
4fill in blank
hard

Complete the code to create a dictionary comprehension that maps each word to its length for words longer than 3 letters.

Intro to Computing
{word: len(word) for word in words if len(word) [1] 3}
Drag options to blanks, or click blank then click option'
A:
B>
C<
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' causes syntax errors.
Using '<' instead of '>' changes the filter condition incorrectly.
5fill in blank
hard

Fill all three blanks to create a dictionary from a list of tuples, where keys are names in uppercase and values are ages greater than 20.

Intro to Computing
result = [1]: [2] for name, age in data if age [3] 20}
Drag options to blanks, or click blank then click option'
Aname.upper()
Bage
C>
Dname.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using name.lower() instead of uppercase changes keys incorrectly.
Using = instead of > causes syntax errors.
Swapping keys and values causes wrong dictionary structure.