0% found this document useful (0 votes)
9 views

Learn Data Types Variables and Input

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Learn Data Types Variables and Input

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

This lesson is

being
recorded
APPLY TASK ANSWER
WEEK 2
Starter

What is a Data Type?

Theory Past Paper Mark Scheme Video


Starter

What is a Data Type?

Each variable in a program must have a


data type. The data type determines what
type of value the variable will hold.

Theory Past Paper Mark Scheme Video


Edexcel iGCSE Computer
Science

2.3.1 Data types


2.3.4 Variables & Constants
Syllabus
Learning Objectives

Understand the need for data types

Understand how to use, data types (integer, real, Boolean, char, string)

Understand the need for, and how to use, variables and constants
Textbook Reference

Although there are lots of resources available for this


qualification, your lessons refer to this textbook.
Pearson Edexcel International GCSE (9-1)
Computer Science Student Book
2.3.1 pages 35 - 37
2.3.4 pages 8,9 – 35,37
Data Types
Algorithms use variables (named memory locations) to store values. Variables have a variety of uses.

For example
 controlling the number of times a loop is executed
 determining which branch of an IF statement is taken
 keeping running totals and holding user input.

When algorithms are converted into programs, the computer needs to be told what type of data is stored
in each variable. This is called CASTING or ASSIGNING or INITIALISING .

Every programming language has a number of built-in data types.


Data Types
Data Types
When writing pseudocode, you don’t have to specify the data types of variables.

For example, the result of multiplying a value by 5 differs according to its data type.

Data Type Example


Integer 8 * 5 = 40

Real 8.0 * 5 = 40.0

Character ‘8’ * 5 = ‘88888’


Data Types - examples
When a variable/constant is declared, the computer gives it a location in its memory.
Initially, this location is empty, so before a variable can be used it has to be given a value.

You can put an initial value into a variable/constant by:


 initialising it when the program is run (e.g. SET total TO 0, in pseudocode)
 reading a value from a keyboard or other device (e.g. RECEIVE admissionCharge FROM
(INTEGER) KEYBOARD).
Once a variable/constant has been initialised an assignment statement is used to change its value
(e.g. SET total TO total + admissionCharge).

In Python this would be:


total = 0
total = total + admissionCharge
Constants

When we want to write computer programs we often need to store simple pieces of data temporarily in the
program for further use.

We do this using a combination of constants and variables, using the format name = value.

Whenever we store data that doesn’t change we store it in a constant, usually designated in Python as all
CAPITALS.

For example if we want to store the value of Pi, we can create a PI constant.

PI = 3.142
Variables
If we want to store the value of some data that might change, we use a similar system, but instead we use
lowercase letters.

player_name = "Bob“

A variable is a named space in a computer’s memory where we can store things and that we can change
(vary) the things that are stored in that memory.

It is important to note that Python and many other programming languages don’t recognise the difference
between variables and constants and so they will let you change a constant, even if you shouldn’t!
Python Naming Conventions
In Python, following naming conventions is important for writing clean and readable code. Here are some
commonly accepted naming conventions in Python:

Variable Names
Use lowercase letters and separate words with underscores to improve readability. For example:

my_variable = 10
user_name = "John”

Function Names
Use lowercase letters and separate words with underscores for function names as well. For example:

def
calculate_average(numbers_list):
pass
Python Naming Conventions
Constant Names
Use uppercase letters and separate words with underscores for constants, which are values that do not
change.

For example:

MAX_VALUE = 100
PI = 3.14

Remember that these conventions are not strict rules enforced by the Python language itself, but they are
widely followed in the Python community.

Consistently applying these naming conventions will make your code more readable and make it easier for
others to understand and collaborate on your code.
Python Naming Conventions
Variables can contain all kinds of information. Let’s look at a few examples:

What do you notice about how these variables


are named?

It is important to use meaningful names – this


studentAge = 14 means that anyone can look at the code and
heightInM = 1.61 know what the variable relates to.

orderPaid = True Use camelCase to show the start of each word


gender = ‘F’ within the variable name.

Do this in all the code you write to make it easy


for other people (and you) to read and
understand.
Plenary
Use the following summary and video link to make notes for your Apply task.

https://www.youtube.com/watch?v=9QIFXyBYJQY&list=PL04uZ7242_M5F0O5YicE_oxG0e2rvWq-q&index=5
Plenary
Use the following summary and video link to make notes for your Apply task.

https://www.youtube.com/watch?v=9QIFXyBYJQY&list=PL04uZ7242_M5F0O5YicE_oxG0e2rvWq-q&index=5
Syllabus
APPLY TASK
Check your ‘to do’ list
for your Apply task
Deadline 1 week
Lesson complete!
See you next lesson

You might also like