TalentJR

🐍 Python for kids · Class 6 · Lesson 8 of 18 · Free

Boolean Logic – and, or, not

⏱ About 30 minutes · ▶ run real Python here — nothing to install · no sign-in

In this lesson you will

  • Explain what True and False mean and store them in variables.
  • Combine conditions with and, or and not to make one decision.
  • Use brackets to control the order when a rule has many parts.

A water park ride has a sign: over 120 cm AND at least 8 years old. Another sign says: free entry on your birthday OR with a school ID. Python checks rules like these with three small words.

What is a Boolean in Python?

A Boolean is a value that is either True or False. There is nothing in between.

Every comparison gives a Boolean. 10 > 3 is True, and 2 == 5 is False.

You can store a Boolean in a variable, just like a number. Then use the variable in an if.

🐍 Python — you can edit this code
Output
Is a teen? False
Has ticket? True
<class 'bool'>

💡 True and False start with a capital letter. true without a capital is just an unknown name.

How does and work in Python?

and joins two conditions. The result is True only when both sides are True.

If even one side is False, the whole thing is False. It is a strict rule.

Python is also lazy in a smart way. If the left side is already False, it does not check the right side.

Here a student passes only if they score at least 35 in theory and in practical.

🎬 How Python thinks — step 1 of 5Python is about to run line 1
▶theory = 52
2practical = 30
3if theory >= 35 and practical >= 35:
4 print("Pass")
5else:
6 print("Fail – both parts need 35")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Fail – both parts need 35

💡 Change practical to 40 and run it again. Now both sides are True, so the result is Pass.

How does or work in Python?

or is more relaxed. The result is True when at least one side is True.

It is False only when both sides are False.

So and is like a strict gatekeeper, and or is like a kind one. Pick the one that matches your rule.

Below, a museum gives free entry to children under 5 or to seniors aged 60 and above.

🎬 How Python thinks — step 1 of 14Python is about to run line 1
▶for age in [3, 12, 35, 65]:
2 if age < 5 or age >= 60:
3 print(age, "-> free entry")
4 else:
5 print(age, "-> ticket needed")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
3 -> free entry
12 -> ticket needed
35 -> ticket needed
65 -> free entry

What does not do in Python?

not flips a Boolean. not True is False, and not False is True.

It makes code read like English. if not is_raining sounds like a normal sentence.

not is also handy with in. It checks that something is missing from a list.

🐍 Python — you can edit this code
Output
Let's play cricket outside!
What are you bringing to the exam? calculator
calculator is allowed.

How do I combine and, or and not with brackets?

Big rules often mix and with or. Python does and before or, just like × comes before + in maths.

Brackets make your meaning clear. Python works out the brackets first.

The leap year rule is a famous example. A leap year divides by 4 but not by 100.

There is one exception: a year that divides by 400 is also a leap year.

🎬 How Python thinks — step 1 of 14Python is about to run line 1
▶for year in [2024, 1900, 2000, 2026]:
2 leap = (year % 4 == 0 and year % 100 != 0) or year % 400 == 0
3 print(year, "leap year?", leap)
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
2024 leap year? True
1900 leap year? False
2000 leap year? True
2026 leap year? False

💡 1900 divides by 4 but also by 100, so it was not a leap year. 2000 divides by 400, so it was.

How do I use Boolean logic in a real program?

A login check is a perfect use. The username and the PIN must both be correct.

We also give a clear message for each kind of mistake. That needs and, or and not together.

Store parts of a rule in well-named variables. Then the if line reads like a sentence.

Try the inputs aarav and 2468, then two wrong values. Each path of the if gives a different message.

🐍 Python — you can edit this code
Output
Username: aarav
PIN: 1357
One of them is wrong. Try again.

🤔 Predict the output

Think like Python: read the code and choose what it prints. You get the reason straight away.

Question 1. What does this print?

a = 8
print(a > 5 and a < 10)
print(a > 5 and a > 10)

Question 2. What does this print?

x = 4
print(x == 1 or x == 4, not x == 4)

Question 3. What does this print?

print(True or False and False)

🧩 Your challenge

Write a cinema rule checker. Ask for the viewer's age and whether they are with a parent (yes or no). A U/A 13+ film allows anyone aged 13 or more, or anyone younger who is with a parent. Print "You can watch" or "Sorry, not allowed".

Expected output (with the inputs given):
Your age: 11
With a parent? (yes/no) yes
You can watch
🐍 Python — you can edit this code

⚠️ Common mistakes (and how to fix them)

❌ Wrong

colour = "blue"
if colour == "red" or "green":
    print("Traffic light colour!")

No error message – but it prints "Traffic light colour!" even for blue.

✅ Right

colour = "blue"
if colour == "red" or colour == "green":
    print("Traffic light colour!")

"green" alone counts as True, so the or is always True. Write the full comparison on each side.

❌ Wrong

marks = 75
if marks >= 60 And marks < 80:
    print("First class")

SyntaxError: invalid syntax

✅ Right

marks = 75
if marks >= 60 and marks < 80:
    print("First class")

Python keywords are all small letters. Write and, or, not – never And or AND.

❌ Wrong

is_holiday = false
if not is_holiday:
    print("School today")

NameError: name 'false' is not defined

✅ Right

is_holiday = False
if not is_holiday:
    print("School today")

The Boolean values are True and False with capital letters. false is treated as an unknown variable.

📌 Remember

  • A Boolean is either True or False; every comparison gives one.
  • and is True only when both sides are True.
  • or is True when at least one side is True.
  • not flips True to False and False to True.
  • Python does and before or; use brackets to make the order clear.
  • Write full comparisons on both sides: x == 1 or x == 2.

Finished the quiz and the challenge?

Questions students ask

What is Boolean logic in Python?

Boolean logic is working with True and False values. You join them with and, or and not to make decisions.

Which comes first in Python, and or or?

and is worked out before or. Use brackets whenever you mix them, so the code is easy to read.

Why is my or condition always True?

You probably wrote x == "a" or "b". The text "b" counts as True on its own. Write x == "a" or x == "b" instead.

Can I use not with in?

Yes. item not in my_list is True when the item is missing from the list. It reads like plain English.