TalentJR

🐍 Python for kids · Class 5 · Lesson 9 of 18 · Free

Combining Conditions – and, or, not

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

In this lesson you will

  • Join two conditions with and, so both must be True.
  • Use or when any one condition is enough.
  • Flip a True or False answer with not.

Your mother says, "You can play outside if your homework is done AND it is not raining." That is two checks in one sentence. Today Python learns to check two things at once.

Why do we need to combine conditions?

In Lesson 7, each if asked one question, like marks >= 35. Real life often needs two questions together.

You could put one if inside another if. But that gets deep and hard to read.

Python gives three small words to join questions: and, or, not. They are called logical operators.

🐍 Python — you can edit this code
Output
Go and play outside!
Same answer, shorter code!

💡 Both if blocks give the same answer. The second one is easier to read, like an English sentence.

How does the and operator work in Python?

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

Think of a school trip. You can go only if you have the permission slip and you paid the fee. Missing either one means no trip.

Below, Riya scored 82 and her attendance is 90. Both checks pass, so she gets the prize.

🎬 How Python thinks — step 1 of 6Python is about to run line 1
▶marks = 82
2attendance = 90
3if marks >= 75 and attendance >= 85:
4 print("You win the Star Student prize!")
5else:
6 print("Keep trying for the prize.")
7print(marks >= 75 and attendance >= 95)
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
You win the Star Student prize!
False

💡 The last line prints False, because attendance 90 is not >= 95. One False side makes the whole and False.

How does the or operator work in Python?

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

A school is closed on Sunday or on a holiday. Either reason is enough to stay home.

or is False only when both sides are False.

🎬 How Python thinks — step 1 of 5Python is about to run line 1
▶day = input("Which day is it? ")
2holiday = input("Is it a holiday (yes/no)? ")
3if day == "Sunday" or holiday == "yes":
4 print("No school today. Enjoy!")
5else:
6 print("Pack your bag for school.")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Which day is it? Monday
Is it a holiday (yes/no)? yes
No school today. Enjoy!

What does not do in Python?

not flips an answer. not True becomes False, and not False becomes True.

It is handy with True/False variables. if not raining reads just like English.

Use not to check that something has not happened yet.

🐍 Python — you can edit this code
Output
True
Good, the lights are already off.

How do I check if a number is between two values?

A very common job is a range check. For example, is the age between 6 and 12?

We need two checks: age >= 6 and age <= 12. Both must be True, so we use and.

Python also allows a short form: 6 <= age <= 12. It means exactly the same thing.

🎬 How Python thinks — step 1 of 4Python is about to run line 1
▶age = int(input("Enter your age: "))
2if age >= 6 and age <= 12:
3 print("You can join the Junior Coding Club.")
4elif age >= 13 and age <= 17:
5 print("You can join the Senior Coding Club.")
6else:
7 print("Sorry, no club for this age.")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Enter your age: 10
You can join the Junior Coding Club.

Can I use and, or and not together?

Yes. Python checks not first, then and, then or. This is like BODMAS in maths.

To be safe and clear, put brackets around each part. Brackets are checked first, just like in maths.

Here a cricket team qualifies if it wins 5 matches, or wins 4 with a good run rate.

🐍 Python — you can edit this code
Output
Team qualified: True

💡 Brackets make your meaning clear to Python and to anyone reading your code.

🤔 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?

x = 7
print(x > 5 and x < 10)

Question 2. What does this print?

sunny = False
holiday = False
print(sunny or holiday)
print(not sunny)

Question 3. What does this print?

marks = 40
if marks >= 90 or marks < 35:
    print("Special note")
else:
    print("Normal report")

🧩 Your challenge

Build a ride checker for a fun fair. A child can sit on the Giant Wheel if their age is at least 8 and their height is at least 120 cm. Ask for both and print whether they can ride.

Expected output (with the inputs given):
Your age: 10
Your height in cm: 132
Welcome! Enjoy the Giant Wheel.
🐍 Python — you can edit this code

⚠️ Common mistakes (and how to fix them)

❌ Wrong

grade = "C"
if grade == "A" or "B":
    print("Great work!")

No error message – but it prints "Great work!" even for grade C.

✅ Right

grade = "C"
if grade == "A" or grade == "B":
    print("Great work!")

Each side of or must be a full question. A word like "B" alone always counts as True.

❌ Wrong

age = int(input("Age: "))
if age >= 6 or age <= 12:
    print("Junior club")

No error message – but a 40-year-old gets into the Junior club.

✅ Right

age = int(input("Age: "))
if age >= 6 and age <= 12:
    print("Junior club")

For a range check both sides must be True, so use and. With or, almost every number passes.

❌ Wrong

marks = 80
if marks > 50 AND marks < 90:
    print("Good")

SyntaxError: invalid syntax

✅ Right

marks = 80
if marks > 50 and marks < 90:
    print("Good")

Python is case-sensitive. The words and, or, not must be written in small letters.

📌 Remember

  • and is True only when both conditions are True.
  • or is True when at least one condition is True.
  • not flips True to False and False to True.
  • Use and for range checks, like age >= 6 and age <= 12.
  • Each side of and/or must be a full comparison, like grade == "B".
  • Brackets make mixed conditions clear and are checked first.

Finished the quiz and the challenge?

Questions students ask

What is the difference between and and or in Python?

and needs both conditions to be True. or needs only one of them to be True. So and is strict, and or is relaxed.

Can I join more than two conditions?

Yes. You can write a > 0 and b > 0 and c > 0. With and, every part must be True for the whole thing to be True.

Why does if grade == "A" or "B" not work?

Python reads it as two separate parts: grade == "A", and just "B". A non-empty word counts as True, so the if always runs. Write grade == "B" in full.

Which is checked first: and, or, or not?

Python checks not first, then and, then or. Use brackets when you mix them, so your meaning is clear.