T1 Data Types and Operations
T1 Data Types and Operations
Starter
• What is a data type?
• How many can you name?
Starter
• What is a data type?
The kind of values that can be used in a data item
• How many can you name?
integer, real / float, char / character, string, Boolean
• An arithmetic operator is a symbol that will perform
an operation on numbers
• + is an example of an arithmetic operator that uses
two numbers, e.g. 5 + 2
• How many arithmetic operators can you name?
+, -, *, /, ^, MOD, DIV
Data types and operations
Unit 9 Key programming concepts
IGCSE pseudo-code
• Throughout these lessons, computer code will be
written using IGCSE pseudo-code
• Sometimes the syntax may be different
or not possible in the programming
language you are studying
• Sometimes examples will
demonstrate a concept in a
real language – this will be
in Python unless
stated otherwise
Data types and operations
Unit 9 Key programming concepts
Data types
• Variables will typically be one of the following types:
• Integer, Boolean, real, char or string
Declaring variables
• Before using variables they should be declared
• Declaring a variable gets it ready for use in the program
• The data type is given to the variable – the programming
language (compiler) can check that it is being used correctly
• Examples of declaring and using variables
DECLARE sidesInShape : INTEGER
DECLARE name : STRING
sidesInShape ← 4
Name ← "Jody"
Data types and operations
Unit 9 Key programming concepts
Constants
• As well as variables, you can define constants
in a program
CONSTANT Pi ← 3.14157926535
CONSTANT VAT ← 0.2
CONSTANT MaxPlayers ← 6
Constants
• Why declare a constant instead of a variable?
• This prevents the value from being changed accidentally by a
part of code
• It shows a programmer that the value should stay the same
throughout the program
• Can a constant ever change its value?
• A constant cannot be changed when the program is running
• A constant can be changed by a programmer before the
program is compiled or translated
Data types and operations
Unit 9 Key programming concepts
INPUT statement
• In many high-level programming languages such as
Python, an input statement can have a prompt for
the user:
firstName = input("What is your name? ")
• This statement first displays the message “What is
your name?” and then waits for the user to enter
some text and press Enter
• The response is then assigned to the
variable firstName
Data types and operations
Unit 9 Key programming concepts
Arithmetic operators
• The operators +, -, * and / are used for addition,
subtraction, multiplication and division
• ^ is used for an exponent (power of)
• daysLeft ← 31 MOD 7
• The variable daysLeft is assigned the value 3
• This is because the remainder after the division is 3
Data types and operations
Unit 9 Key programming concepts
Orders of precedence
• Remember BIDMAS
• Brackets
• Indices
• Division
• Multiplication
• Addition
• Subtraction
• Calculate: x ← (5 – 2) + (16 – 6 / 2)
y ← 7 * 3 + 10 / 2
Are brackets needed in the first expression?
Data types and operations
Unit 9 Key programming concepts
Worksheet 1
• Now complete Task 1 on Worksheet 1
Data types and operations
Unit 9 Key programming concepts
• In Python:
tickets = int(input("Please enter number of tickets required: "))
Concatenating strings
• Concatenating means joining together
• The + concatenate operator is used to join together strings
firstname ← "Rose"
surname ← "Chan"
fullname ← firstname + " " + surname
OUTPUT fullname
• What will be output?
• What will be output by the program?
x ← "6" + "3"
OUTPUT x
Data types and operations
Unit 9 Key programming concepts
Concatenating strings
firstname ← "Rose"
surname ← "Chan"
fullname ← firstname + " " + surname
OUTPUT fullname
• What will be output? "Rose Chan"
• What will be output by the program
x ← "6" + "3"
OUTPUT x
"63"
Data types and operations
Unit 9 Key programming concepts
String handling
• What is the output of the following program?
a ← "The quality of mercy is not strained."
b ← LENGTH(a) – 30 b ← 37 - 30
b ←7
c ← SUBSTRING(a,1,b)
c ← "The qua"
d ← SUBSTRING(c,1,LEN(c)-1)
d ← "The qu"
Using comments
• You should use comments in your programs:
• to describe the purpose of the program
• to state the author of the program
• to explain what the code does
Worksheet 1
• Now complete Task 2 and Task 3 on Worksheet 1
Data types and operations
Unit 9 Key programming concepts
Plenary
• In pairs give:
• 5 different data types
• 4 arithmetic operators
• 3 functions used for string operations
• 2 arithmetic operators used for integer division and remainder
• 1 concatenate operator
Data types and operations
Unit 9 Key programming concepts
Plenary
• 5 different data types
• Integer, real / float, char / character, string, Boolean
• 4 arithmetic operators +, -, *, /, ^
• 3 functions used for string operations
• LENGTH(string), LCASE(string), UCASE(string),
SUBSTRING(string, start, length)
• 2 arithmetic operators used for integer division and
remainder
• DIV (integer division), MOD (remainder)
• 1 concatenate operator +
Data types and operations
Unit 9 Key programming concepts
Copyright
This unit and all the worksheets, PowerPoint presentations, teaching guides and other associated files
distributed with it are supplied to you by PG Online Limited under licence and may be used and copied by you
only in accordance with the terms of the licence. Except as expressly permitted by the licence, no part of the
materials distributed with this unit may be used, reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic or otherwise, without the prior written permission of PG Online Limited.
Licence agreement
This is a legal agreement between you, the end user, and PG Online Limited. This unit and all the worksheets,
PowerPoint presentations, teaching guides and other associated files distributed with it is licensed, not sold, to
you by PG Online Limited for use under the terms of the licence.
The materials distributed with this unit may be freely copied and used by members of a single institution on a
single site only. You are not permitted to share in any way any of the materials or part of the materials with any
third party, including users on another site or individuals who are members of a separate institution. You
acknowledge that the materials must remain with you, the licencing institution, and no part of the materials may
be transferred to another institution. You also agree not to procure, authorise, encourage, facilitate or enable any
third party to reproduce these materials in whole or in part without the prior permission of PG Online Limited.