GCSE · Computer Science · Edexcel · Spec 1CP2

Logical operator AND

The five of hearts is a heart, but it is not the king. Does it pass the check "king and hearts"? Four routes, and only one gets through.

Computer Science · and

Four routes, one way through

Pick a value for A, then a value for B. Reveal where the route ends.

The two conditions → Condition A → Condition B

4 routes.

On A and B. 2 branches to choose from.

Two conditions, A and B, each True or False. Walk every route and see what A and B ends up as.

Exam line: A and B is True only on the route where A is True and B is True. Any route with a False in it ends in False.
Watch out: Do not let one matching condition fool you. "One match is enough" is the rule for or, not for and.

Try it on a real card

The five of hearts walks up to the check

A program is checking the five of hearts with this expression: value == "king" and suit == "hearts". The value of the card is 5 and its suit is "hearts".

What does the expression work out to? Pick the idea closest to what you think, then say how sure you are.
How sure are you?

Computer Science · Algorithms

Trace table — dry run the code

Step through the program one line at a time. Watch each condition get its own True or False, then watch and join them.

1value = 5
2suit = "hearts"
3if value == "king" and suit == "hearts":
4 print("My card is a match")
5else:
6 print("My card is not a match")
value
suit
value == "king"
suit == "hearts"
and result
Output
Press Start to run the first line.
·

Ready when you are — step through one line at a time.

Building a range

Two comparisons, one variable

adult_ticket = age > 12 and age < 60. Work out what adult_ticket is when age is 60.

  1. age is 60, so work out each comparison on its own first.
  2. missing step
Which line is step 2?

Now you write one

Build the expression yourself

Cards: the five of hearts, the ten of hearts, the ten of spades, the nine of diamonds. The variables are called value and suit.

Write one logical expression that uses and to check that a card has a value less than or equal to 10 and is of the suit hearts. Then say whether your expression is True or False for each card in the stimulus. [5 marks]

0 words · your answer stays on this page and is not sent anywhere.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Four routes. Only one way through.

What you need to know

  • A logical expression always works out to True or False.
  • The three basic logical operators are 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 says: "True and False is True. Well, one of them is True, and that counts!" Is Sam right?

    No. True and False is False.

    With and, both conditions must be True, so one True is not enough. Sam is thinking of a different operator.

  • 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. The suit matches, but the value is not king.
  • Have a goNow try the king of hearts. What does value == "king" and suit == "hearts" give?

    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 is the result?

    age > 12 fails. The result is False.

    8 > 12 is False. It does not matter that 8 < 60 is True, because one False sinks the whole expression.

  • To meet a requirement, write one comparison per condition and join them: value <= 10 and suit == "hearts".
  • Inside an if statement, a False and expression sends the program to the else branch.

The big picture

A logical expression always works out to True or False. With and, the whole expression is True only when both conditions are True. One False anywhere and the whole thing is False. That is how programs decide which branch of an if statement to run.

Key points

1A logical expression works out to either True or False.
2and is True only when both conditions are True. One False makes the whole expression False.
3Of the four combinations of two conditions, only True and True gives True.
4Logical operators join relational comparisons, such as age > 12, into one True or False.
5An and expression can control a selection statement: False means the else branch runs.

Worked example

Problem

A game gives a bonus when score > 50 and lives == 3. A player has a score of 80 and 2 lives. Is the bonus given?

⚠ Watch out

Reading and as "one match is enough". That is the rule for or. With and, the five of hearts fails value == "king" and suit == "hearts" because the value is not king, even though the suit matches.

🧠

Memory hook

Think of and as a door with two locks. Both keys must turn. One missing key and the door stays shut.

✓

Check yourself

Without looking back: a program checks two conditions joined with and. The first is True and the second is False. What does the whole expression give, and why is one False enough to decide it?

Flashcards

(12)
What can a logical expression evaluate to?
Either True or False.
Name the three basic logical operators.
and, or and not.
What does a logical expression combine?
Relational operators (such as >, < and ==) and logical operators.
When is A and B True?
Only when both A and B are True.
One condition in an and expression is False. What is the whole expression?
False. If either condition is False, the whole expression is False.
False and False gives...?
False. Two Falses do not make a True. There is still no True and True.
There are four combinations of two conditions. How many give True with and?
Just one: True and True.
Five of hearts: what does value == "king" and suit == "hearts" give?
False. The suit matches, but the value is not king.
Five of hearts: what does value == 5 and suit == "hearts" give?
True. Both conditions are True.
How do you write "age is above 12 and also below 60"?
age > 12 and age < 60
How do you check for a value less than or equal to 10 and the suit hearts?
value <= 10 and suit == "hearts"
An if statement uses an and expression that works out False. Which branch runs?
The else branch. For the five of hearts it displays "My card is not a match".

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 posted

More Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

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 9 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.