GCSE · Computer Science · Edexcel · Spec 1CP2
Logical operator AND
The five of hearts meets a check for "king and hearts". Right suit, wrong value. Does it get in? Four routes, and only one leads to True.
Computer Science · and
Four routes, one way through
Pick a value for A, then a value for B. Before you reveal the end, guess: True or False?
The two conditions → Condition A → Condition B
4 routes.
Two conditions, A and B, each True or False. Walk all four routes and see where A and B ends up.
Computer Science · Algorithms
Trace table — dry run the code
Step through the program a line at a time. Watch each comparison come out True or False, then watch and turn them into one answer that picks the branch.
Ready when you are — step through one line at a time.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Four routes. Only one way through.
What you need to know
- Every logical expression ends up as one of two values: True or False.
- There are three basic logical operators: and, or and not. This lesson is all about and.
- Logical operators join relational comparisons, like age > 12, so several checks boil down to one True or False.
- With and, both conditions must be True. If either one is False, the whole expression is False.
Have a goSam is confident: "True and False is True. One of them is True, so that counts, right?" Is Sam right?
No. True and False is False.
With and, both conditions must be True, so one True isn't enough. Sam's idea is wrong for and.
- Only True and True gives True. True and False, False and True, and False and False all give False.
- Five of hearts: value == "king" and suit == "hearts" is False. Right suit, wrong value.
Have a goSwap in the king of hearts. What does value == "king" and suit == "hearts" give now?
True.
The value is king and the suit is hearts. Both conditions are True, so the whole expression is True.
- Range check: age > 12 and age < 60 is True only when age is above 12 and also below 60.
Have a goage is 8. Which condition in age > 12 and age < 60 fails, and what's the result?
age > 12 fails, so the result is False.
8 > 12 is False. It doesn't matter that 8 < 60 is True, because one False sinks the whole and expression.
- To meet a requirement, write one full comparison per condition and join them: value <= 10 and suit == "hearts".
- In an if–else, a False and expression skips the if branch, so the else branch runs.
The big picture
A logical expression always ends up as True or False. With and, the whole thing is True only when both conditions are True. One False anywhere and the whole expression is False. Put that inside an if statement and it decides which branch the program runs.
Key points
Worked example
Problem
A game gives a bonus when score > 50 and lives == 3. A player has a score of 80 and 2 lives. Do they get the bonus?
⚠ Watch out
Reading and as "one match is enough". That idea is wrong for and. With and, the five of hearts fails value == "king" and suit == "hearts" because the value isn't king, even though the suit matches.
Memory hook
and is a door with two locks. Both keys have to turn. One key that won't turn and the door stays shut, however well the other one works.
Check yourself
No peeking: a program tests two conditions joined with and. The first comes out True, the second False. What does the whole expression give, and why is one False enough to settle it?
Flashcards
(12)What can a logical expression evaluate to?
Name the three basic logical operators.
What does a logical expression combine?
When is A and B True?
One condition in an and expression is False. What is the whole expression?
False and False gives...?
Two conditions give four combinations. How many of them make and True?
Five of hearts: what does value == "king" and suit == "hearts" give?
Five of hearts: what does value == 5 and suit == "hearts" give?
Write "age is above 12 and also below 60" as one expression.
Write a check for a value less than or equal to 10 and the suit hearts.
An if–else statement's and expression comes out False. Which branch runs?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 26 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.