Class Notebook page is 2 1 Variables Lesson

Class Notebook page is > 2. 1 Variables Lesson 2 1. List the variable name on the image 2. Explain why a variable is used 3. Explain why we name variables Stretch: Why are some words in blue? Hint: Look back at last lessons work © OCR 2017

Variable Rules • Variables are used to store information, they can be changed as it says in the name. Variable > Vary! • We want variable names to describe their values, like naming your pet says something about its character or appearance, remember what Mr Frith said about the box example! • A 1 or B 2 tell us absolutely nothing about their values except where to find them – not good enough! © OCR 2017

Constant = Value that cannot be changed in a program Variable = Value that can be changed in a program Both variables and constants have a name and a value. The value is the actual data your program needs to remember (e. g. the number 3. 141) The name lets your program call that value something more helpful (e. g. PI) © OCR 2017

Naming variables = 1. Explain why we renamed A 1 and B 1 to first_num and second_num? 2. Explain what problems you could have if you didn’t change the variable name? © OCR 2017

Variable vs Constant © OCR 2017

INPUT - OUPUT - PROCESSING INPUT OUTPUT PROCESSING OUTPUT © OCR 2017

Types of Variables (Data Types) What would we do if we wanted the computer to run our program as text? Or numbers? We have to assign a variable a data type so the computer knows if we are working in text, whole numbers, real numbers ect. Give an example for each one of these: • Whole number (no decimals/fractions), e. g. room number • Real number (has a fractional part), e. g. Pi, or test average • String (any text that isn’t meant to be calculated), e. g. a person’s name • Boolean (True or False), e. g. “was there homework assigned yesterday? ” © OCR 2017

Types of Variables (Data Types) Data Example Data Type Age 14 Integer Shoe Size 6. 5 Float Price 14. 99 Postcode Height Quantity in Stock Telephone Number 1. Explain why different data types are needed 2. Why would we need to set our variable as a Data Type? 3. Attempt to write some Pseudocode with a Data Type included © OCR 2017

Find and correct the four errors made in this piece of programming © OCR 2017

Find and correct the four errors made in this piece of programming © OCR 2017
- Slides: 10