Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1student['name'] | AGets the value of the field called name from a dictionary record | |
| 2student[0] | BIndex 3 is out of range. The record has 3 fields, so the valid indexes are 0, 1 and 2. Use student[2] for the last field. | |
| 3A tuple is an unchangeable record, so its fields can be read but not reassigned | Cname, age, year = student | |
| 4Unpacking copies each field of a record into its own variable in one line | Dstudent = ('Ava', 17, 'Year 12') | |
| 5student = ['Ava', 17, 'Year 12'] print(student[3]) | EThe field name is missing quotes, so Python looks for a variable called name. It should be student['name']. | |
| 6student = {'name': 'Ava', 'age': 17} print(student[name]) | FGets the first field of a list or tuple record by its field index |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
student['name'] — Gets a field from a record by its field name. A list or tuple record uses the field index (its position) instead, such as student[0]. Indexes start at 0.student = ['Ava', 7, 'Red']
print(student[0])student = ('Ava', 7, 'Red')
print(student[2])student = {'name': 'Ava', 'year': 7}
print(student['year'])student = ('Ava', 7, 'Red')
name, year, house = student
print(name)student = {'name': 'Ava', 'year': 7}
print(student['name'])