GCSE · Computer Science · AQA · Spec 8525
NOT (Boolean operator in code)
'Keep guessing until you get it right.' Every guessing game runs on that one sentence. Turning it into code takes one tiny word that swaps True and False round: 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.
Have a goYour mate insists NOT always means False, so NOT False must be False too. Who's right, and what is NOT False?
Not your mate. NOT False is True.
NOT doesn't mean 'False'. It means 'the opposite', so it turns False into True just as it turns True into False.
- You can put NOT in front of a Boolean variable, like NOT correct, in an IF or a loop condition.
- It works on a comparison too, like NOT (score > 50), because a comparison gives True or False.
Have a gotemp is 30. Is NOT (temp < 20) True or False?
True
30 < 20 is False, and NOT reverses that to True. Answering False means you worked out the comparison but forgot to apply the NOT.
- NOT works out a value for that one test. The variable keeps exactly what it stored.
- Only an assignment, such as correct ← True, changes what a variable holds.
- So a loop like WHILE NOT found runs while found is False, and stops once found becomes True.
Have a godone ← False, then WHILE NOT done… but nothing inside the loop ever assigns done. How many times does the loop run?
It never stops: it runs forever.
done stays False because only an assignment could change it, so NOT done is True at every check. NOT itself never sets done to True.
- Combine NOT with AND or OR and the brackets decide what it reverses: bracket first, then reverse that one answer.
- No brackets? Then NOT reverses just the value straight after it.
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 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.