Computer Science GCES OCR
-
Cpu Architecture Performance And Embedded Systems Ocr5 主题
-
Primary And Secondary Storage Ocr6 主题
-
Data Storage And Compression Ocr12 主题
-
Units Of Data Storage Ocr
-
Processing Binary Data Ocr
-
Data Capacity And Calculating Capacity Requirements Ocr
-
Converting Between Denary And Binary Ocr
-
Binary Addition Ocr
-
Converting Between Denary And Hexadecimal Ocr
-
Converting Between Binary And Hexadecimal Ocr
-
Binary Shifts Ocr
-
Representing Characters Ocr
-
Representing Images Ocr
-
Representing Sound Ocr
-
Compression Ocr
-
Units Of Data Storage Ocr
-
Networks And Topologies Ocr6 主题
-
Wired And Wireless Networks Protocols And Layers Ocr6 主题
-
Identifying And Preventing Threats To Computer Systems And Networks Ocr2 主题
-
Operating Systems And Utility Software Ocr2 主题
-
Ethical Legal Cultural And Environmental Impact Ocr2 主题
-
Computational Thinking Searching And Sorting Algorithms Ocr3 主题
-
Designing Creating And Refining Algorithms Ocr5 主题
-
Programming Fundamentals And Data Types Ocr5 主题
-
Additional Programming Techniques Ocr7 主题
-
Defensive Design And Testing Ocr6 主题
-
Boolean Logic Diagrams Ocr2 主题
-
Programming Languages And Integrated Development Environments Ides Ocr3 主题
-
The Exam Papers Ocr2 主题
-
Structuring Your Responses Ocr3 主题
Data Types Ocr
Exam code:J277
Primitive Data Types
What is a data type?
-
A data type is a classification of data into groups according to the kind of data they represent
-
Computers use different data types to represent different types of data in a program
-
The basic data types include:
|
Data type |
Used for |
Example |
|---|---|---|
|
Integer |
Whole numbers |
10, -5, 0 |
|
Real |
Numbers with a fractional part |
3.14, -2.5, 0.0 |
|
Character |
Single character |
‘a’, ‘B’, ‘6’, ‘£’ |
|
String |
Sequence of characters |
“Hello world”, “ABC”, “@#!%” |
|
Boolean |
True or false values |
True, False |
-
It is important to choose the correct data type for a given situation to ensure accuracy and efficiency in the program
-
Data types can be changed within a program, this is called casting
What is casting?
-
Casting is when you convert one data type to another data type
Example
-
The following Python program is used to capture a users age to determine if they are old enough to vote
|
Line |
Python code |
|---|---|
|
01 |
age = input(“Enter age”) |
|
02 |
if age >= 18: |
|
03 |
print(“Old enough to vote”) |
|
04 |
else: |
|
05 |
print(“Too young to vote”) |
-
In this example, on line 01, no specific data type is requested
-
By default the data type is stored as ‘string’
-
On line 02, a run-time error would occur because age is stored as a string and is being compared to an integer value in the selection statement
-
Casting the age from a string to an integer would solve the error
|
Line |
Python code |
|---|---|
|
01 |
age = input(“Enter age”) |
|
02 |
if int(age) >= 18: |
|
03 |
print(“Old enough to vote”) |
|
04 |
else: |
|
05 |
print(“Too young to vote”) |
-
In the corrected code, casting is highlighted in green
Casting between data types
|
Conversion |
Example |
Output |
|
From Integer to Real |
|
5.0 |
|
From Real to Integer |
|
5 |
|
From String to Integer |
|
10 |
|
From Integer to String |
|
“5” |
|
From Boolean to String |
|
“True” |
|
From String to Boolean |
|
True |
Worked Example
Customers booking a holiday can choose between half board or all inclusive and a hotel star rating between 1 and 5
A typical booking record is shown in the table:
|
firstName |
Jacob |
|
lastName |
Franks |
|
boardType |
All inclusive |
|
starRating |
5 |
|
bookingComplete |
True |
State the most appropriate data type for the following fields [2]:
|
boardType |
|
|
starRating |
|
Give the name of one field that could be stored as a Boolean data type [1]
Answer
|
boardType |
String |
|
starRating |
Integer |
-
bookingComplete
Responses