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.

On A and B. 2 branches to choose from.

Two conditions, A and B, each True or False. Walk all four routes and see where A and B ends up.

Exam line: A and B is True only on the route where A is True and B is True. Every route with a False in it ends in False.
Watch out: Don't let one matching condition fool you. "One match is enough" is wrong for and: both must be True.

Try it on a real card

The five of hearts walks up to the check

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

What does the expression come out as? 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 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.

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 adult_ticket when age is 60.

  1. age is 60, so find the value of 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 listed. [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

  • 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

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: when it is False, the if branch is skipped and 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. 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?
True or False. Nothing else.
Name the three basic logical operators.
and, or and not.
What does a logical expression combine?
Relational operators (such as >, < and ==) joined by logical operators.
When is A and B True?
Only when A is True and B is True.
One condition in an and expression is False. What is the whole expression?
False. If either condition is False, the whole and expression is False.
False and False gives...?
False. Two Falses don't cancel into a True. There is still no True and True.
Two conditions give four combinations. How many of them make and True?
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. The value is 5 and the suit is hearts, so both conditions are True.
Write "age is above 12 and also below 60" as one expression.
age > 12 and age < 60
Write a check for a value less than or equal to 10 and the suit hearts.
value <= 10 and suit == "hearts"
An if–else statement's and expression comes out False. Which branch runs?
The else branch. For the five of hearts tested with value == "king" and suit == "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 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.