GCSE · Computer Science · AQA · Spec 8525

NOT (Boolean operator in code)

'Keep guessing until you get it right.' Every guessing game runs on that sentence, and turning it into code takes one small word that flips True and False: NOT.

Computer Science · NOT in a loop

Keep guessing until you're right

Step through one line at a time. Keep an eye on two things side by side: what's stored in correct, and what NOT correct works out as.

Before you press Next: correct starts as False. Will the loop run even once?

1 secret ← 7
2 correct ← False
3 WHILE NOT correct
4 guess ← USERINPUT
5 IF guess = secret THEN
6 correct ← True
7 ENDIF
8 ENDWHILE
9 OUTPUT "Got it!"

Variables

secret=7

Output

 

Step 1: The number to guess, 7, is stored in secret.

1 / 14

Press Next to run one line at a time. At every WHILE check, compare correct with NOT correct.

Step 1 of 14: The number to guess, 7, is stored in secret..

Watch out: NOT never changes correct. The only line that changes it is correct ← True. NOT just reads the value and hands the loop the opposite answer.

What does NOT really do?

Which idea do you hold?

finished ← False IF NOT finished THEN OUTPUT "Keep going" ENDIF This code outputs Keep going.

Which idea is closest to what you think NOT did here?
How sure are you?

NOT with AND

Where do the brackets go?

Two programs decide whether to go outside. Program A: IF NOT (raining AND windy) THEN OUTPUT "Go outside". Program B: IF NOT raining AND NOT windy THEN OUTPUT "Go outside". For each kind of day, tick every program whose condition is True.

  • A A: NOT (raining AND windy) is True
  • B B: NOT raining AND NOT windy is True
  1. raining = False, windy = False
  2. raining = True, windy = False
  3. raining = False, windy = True
  4. raining = True, windy = True

Your turn to write it

Write it, then check it

A quiz game uses two Boolean variables, quit and lastLife, and a whole-number variable, points. Using NOT each time, write: (a) the first line of a loop that keeps repeating as long as quit is False; (b) an IF statement that outputs "Bonus!" when the player is not on their last life and has more than 100 points. [4 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.

What you need to know

  • NOT is a Boolean operator. It gives the opposite value: NOT True is False, and NOT False is True.
  • NOT can go in front of a Boolean variable, such as NOT correct, or a comparison, such as NOT (score > 50), in the condition of an IF statement or a loop.
  • NOT works out a value for that test only. It never changes the value stored in the variable.
  • When NOT is combined with AND or OR, brackets decide what it reverses.

The big picture

NOT is a Boolean operator that gives the opposite value of a condition: NOT True is False, and NOT False is True. You put it in front of a Boolean variable or a comparison, inside the condition of an IF statement or a loop. WHILE NOT correct keeps looping while correct is False and stops once correct is True. NOT only works out a value for that test; it never changes what's stored in the variable. When NOT is combined with AND or OR, the brackets decide exactly what it reverses: NOT (raining AND windy) is not the same as NOT raining AND NOT windy.

Key points

1WHILE NOT correct keeps looping while correct is False, and stops at the first check after correct becomes True.
2IF NOT finished THEN runs its code when finished is False.
3NOT (score > 50) is True when score is 50 or less, including 50 itself.
4NOT (a AND b) means 'not both': it's True unless a and b are both True.
5NOT a AND NOT b means 'neither': it's True only when a and b are both False.
6Python writes NOT in lower case: while not correct:

Worked example

Problem

loggedIn is False and attempts is 2. Work out whether each condition is True or False: (a) NOT loggedIn (b) NOT (attempts < 3) (c) NOT loggedIn AND attempts < 3 (d) NOT (loggedIn OR attempts < 3)

⚠ Watch out

Thinking NOT changes the variable. After IF NOT finished runs, finished holds exactly what it held before: NOT only reversed the answer to the test. The only thing that changes a variable is an assignment, such as finished ← True.

🧠

Memory hook

NOT is a mirror, not an eraser. It shows you the answer the other way round, but the variable itself stays exactly as it was.

✓

Check yourself

done is False: what is NOT done, and does IF NOT done change done? With a True and b False, which is True: NOT (a AND b) or NOT a AND NOT b?

Flashcards

(7)
What does NOT do to a True/False value?
It gives the opposite value: NOT True is False, and NOT False is True.
Does NOT change the value stored in a variable?
No. It works out the opposite value just for that test. Only an assignment changes a variable.
When does WHILE NOT found keep looping?
While found is False, because then NOT found is True. It stops at the first check after found becomes True.
What does NOT (a AND b) mean in words?
'Not both.' It's True unless a and b are both True.
What does NOT a AND NOT b mean in words?
'Neither.' It's True only when a and b are both False.
Can NOT go in front of a comparison?
Yes. NOT (score > 50) is True when score is 50 or less.
How do you write NOT in Python?
In lower case: not. For example, while not found:

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 AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)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 30 September 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.