Records: grouping fields of different data types

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Records: grouping fields of different data types

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which best describes a record?
A Stores many values that must all be the same data type
B Groups related fields, which can be different data types, to describe one thing
2. A student record has the fields name, age and mark. Which set of data types fits?
A name: String, age: Integer, mark: Float
B name: Integer, age: String, mark: Boolean
3. How many records would you need to store details of 30 students?
A 1 record that holds all 30 students at once
B 30 records, one per student
4. Which is a field name in a Student record?
A studentName
B "Ava Nguyen"
5. Record or array: you want to store a student's name, age and mark together.
A Record
B Array

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1student = {"name": "Ava", "age": 15, "mark": 88.5} AA record definition that lists each field name and its data type
2Record Student: name String, age Integer, mark Float Bmarks = [88, 74, 91] student = {"name": "Mia", "mark": 91}
3A record holds one item, so you need one record per student Cstudent1 = {"name": "Ava", "age": 15} student2 = {"name": "Liam", "age": 16}
4An array holds values of the same type, but a record can mix data types DTwo students are crammed into one record by repeating a field. Each student needs their own record.
5student = {"name": "Noah", "age": "sixteen"} student["age"] + 1 EThe age field holds text instead of an integer, so maths on it fails. Store it as the integer 16.
6students = {"name": "Zoe", "name": "Leo", "age": 15} FA record for one student that groups a text field, an integer field and a decimal field

Definitions

record

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
student = {"name": "Ava", "age": 15} print(_______["name"])
2.
student = {"name": "Ava", "mark": 87.5} print(____(student["mark"]))
3.
roster = [{"name": "Zoe"}, {"name": "Leo"}] print(roster[_]["name"])
4.
student = {"name": "Ava", "age": 15} print(___(student))
5.
student = {"name": "Ava", "age": 15} ___ field in student: print(field)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A RECORD Student
B name AS String
C age Integer
D mark AS Decimal
E END RECORD
Question 2
A RECORD Book
B title AS Integer
C pages AS Integer
D END RECORD
Question 3
A DIM s AS Student
B s.name = "Ava"
C s.age = "16"
D s.mark = 88.5
Question 4
A ARRAY Pet
B name AS String
C age AS Integer
D END RECORD
Question 5
A DIM s AS Student
B s.name = Noah
C s.mark = 72.5

Answer Key

Records: grouping fields of different data types
Section A: Quick Questions
Q1
B — Groups related fields, which can be different data types, to describe one thing
Q2
A — name: String, age: Integer, mark: Float
Q3
B — 30 records, one per student
Q4
A — studentName
Q5
A — Record
Section B: Match the Pairs
Q1
student = {"name": "Ava", "age": 15, "mark": 88.5} → A record for one student that groups a text field, an integer field and a decimal field
Q2
Record Student: name String, age Integer, mark Float → A record definition that lists each field name and its data type
Q3
A record holds one item, so you need one record per student → student1 = {"name": "Ava", "age": 15} student2 = {"name": "Liam", "age": 16}
Q4
An array holds values of the same type, but a record can mix data types → marks = [88, 74, 91] student = {"name": "Mia", "mark": 91}
Q5
student = {"name": "Noah", "age": "sixteen"} student["age"] + 1 → The age field holds text instead of an integer, so maths on it fails. Store it as the integer 16.
Q6
students = {"name": "Zoe", "name": "Leo", "age": 15} → Two students are crammed into one record by repeating a field. Each student needs their own record.
Section C: Definitions
Q1
record — A structure that groups related fields of different data types to describe one thing, such as a student's name (text), age (integer) and mark (decimal).
Section D: Fill in the Blanks
Q1
student = {"name": "Ava", "age": 15} print(student["name"])
Q2
student = {"name": "Ava", "mark": 87.5} print(type(student["mark"]))
Q3
roster = [{"name": "Zoe"}, {"name": "Leo"}] print(roster[1]["name"])
Q4
student = {"name": "Ava", "age": 15} print(len(student))
Q5
student = {"name": "Ava", "age": 15} for field in student: print(field)
Section E: Spot the Error
Q1
C — Each field in a record must be declared as fieldName AS Type. The AS keyword is missing, so the line should be ' age AS Integer'.
Q2
B — A book title is text, so the field should have the data type String, not Integer. The line should be ' title AS String'. Records can mix data types.
Q3
C — The age field is an Integer, so it must be given a whole number, not text in quotes. The line should be 's.age = 16'.
Q4
A — An array holds items of the same data type, but this structure has a String and an Integer field. A record groups different types, so the line should be 'RECORD Pet'.
Q5
B — A String value must be written inside quotes. Without them, Noah looks like a variable name. The line should be 's.name = "Noah"'.