- Home
- Lessons
- GCSE & IGCSE Computer Science
- Variables, constants and operators
Variables, constants and operators
🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.
Programs store values in variables and constants, then work on them with operators. Integer division and modulus come up in almost every exam.
Variables and constants
A variable is a named store whose value can change while the program runs.
A constant is a named value that does not change, such as VAT = 0.2.
Constants make code easier to read, and if the value ever changes you only edit it in one place.
A constant is a named value that does not change, such as VAT = 0.2.
Constants make code easier to read, and if the value ever changes you only edit it in one place.
Arithmetic operators in Python
Relational and logical operators
Relational: == (equal to), != (not equal to), <, >, <=, >=. They give True or False.
Logical: and, or, not combine True/False values.
(age >= 13) and (age <= 19) is True only for teenagers.
Remember: = assigns a value, == compares two values.
Logical: and, or, not combine True/False values.
(age >= 13) and (age <= 19) is True only for teenagers.
Remember: = assigns a value, == compares two values.
A school has 230 students and each minibus seats 16. Use integer division and modulus to find how many buses are full and how many students are left over.
- 230 // 16 = 14 full buses
- 230 % 16 = 6 students left over
Answer: 14 full buses and 6 students left over
Variables change, constants do not. // gives the whole-number part of a division and % gives the remainder. == compares, = assigns. and, or, not combine conditions.
The interactive lesson includes the diagrams for this topic.
Check you have got it
Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.