T1 Programming Fundamentals
T1 Programming Fundamentals
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, float / real, 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
Programming fundamentals
Unit 7 Programming
Data types
• Variables will typically be one of the following types:
• Integer, Boolean, real / float, character or string
Constants
• As well as variables, you can define constants
in a program
const PI = 3.14157926535
const VAT = 0.2
const MAX_PLAYERS = 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
Programming fundamentals
Unit 7 Programming
INPUT statement
• 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
Programming fundamentals
Unit 7 Programming
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
Programming fundamentals
Unit 7 Programming
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?
Programming fundamentals
Unit 7 Programming
Worksheet 1
• Now complete Task 1 on Worksheet 1
Programming fundamentals
Unit 7 Programming
Concatenating strings
• Concatenating means joining together
• The + concatenate operator is used to join together strings
firstname = "Rose"
surname = "Chan"
fullname = firstname + " " + surname
print(fullname)
• What will be output?
• What will be output by the program?
x = "6" + "3"
print(x)
Programming fundamentals
Unit 7 Programming
Concatenating strings
firstname = "Rose"
surname = "Chan"
fullname = firstname + " " + surname
print(fullname)
• What will be output? "Rose Chan"
• What will be output by the program
x = "6" + "3"
print(x)
"63"
Programming fundamentals
Unit 7 Programming
b = a.length – 10 b = 37 - 30
b = 7
c = a.substring(0,b) c =
a.substring(0,7)
c = "The qual"
d = c.upper d = "THE QUAL"
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
Programming fundamentals
Unit 7 Programming
Plenary
• In pairs give:
• 5 different data types
• 4 arithmetic operators
• 3 functions used for type conversion / casting
• 2 arithmetic operators used for integer division and remainder
• 1 concatenate operator
Programming fundamentals
Unit 7 Programming
Plenary
• 5 different data types
• Integer, real / float, character, string, Boolean
• 4 arithmetic operators
• +, -, *, /, ^
• 1 concatenate operator +
Programming fundamentals
Unit 7 Programming
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.