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 ← 72 correct ← False3 WHILE NOT correct4 guess ← USERINPUT5 IF guess = secret THEN6 correct ← True7 ENDIF8 ENDWHILE9 OUTPUT "Got it!"
Variables
Output
Step 1: The number to guess, 7, is stored in secret.
Press Next to run one line at a time. At every WHILE check, compare correct with NOT correct.
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
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?
Does NOT change the value stored in a variable?
When does WHILE NOT found keep looping?
What does NOT (a AND b) mean in words?
What does NOT a AND NOT b mean in words?
Can NOT go in front of a comparison?
How do you write NOT in Python?
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 AQA GCSE Computer Science topics
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.