Sometimes you need to check multiple conditions at once. For example:
n % 2 == 0 checks if n is even.
To check if both n and m are even, combine conditions with the logical and:
n % 2 == 0 and m % 2 == 0
Logical operators in Python
Operator
Meaning
Returns True if…
Example
and
Logical AND
both operands are True
a > 0 and b > 0
or
Logical OR
at least one operand is True
a > 0 or b > 0
not
Logical NOT (negation)
the operand is False
not (a > 0)
Examples
1) Both numbers are even
n = 4
m = 8
if n % 2 == 0 and m % 2 == 0:
print("Both are even")
2) At least one number ends with 0
a = 25
b = 40
if a % 10 == 0 or b % 10 == 0:
print("At least one ends with 0")
3) Positive and non-negative check
a = 5
b = 0
if a > 0 and not (b < 0):
print("a is positive and b is non-negative")
# Equivalent without 'not'
if a > 0 and b >= 0:
print("a is positive and b is non-negative")
Truth tables
and operator:
A
B
A and B
True
True
True
True
False
False
False
True
False
False
False
False
or operator:
A
B
A or B
True
True
True
True
False
True
False
True
True
False
False
False
not operator:
A
not A
True
False
False
True
Tips
Use parentheses (...) to make complex logic easier to read.
Short-circuit evaluation: and stops if the first operand is False, or stops if the first operand is True.
not flips the boolean value: not True → False, not False → True.
Quick practice
Check if both entered numbers are positive.
Check if at least one of the numbers is divisible by 5.
Check if a number is not between 10 and 20 (inclusive).
Show sample solutions
# 1) Both positive
a, b = map(int, input().split())
print(a > 0 and b > 0)
# 2) At least one divisible by 5
a, b = map(int, input().split())
print(a % 5 == 0 or b % 5 == 0)
# 3) Not between 10 and 20 inclusive
n = int(input())
print(not (10 <= n <= 20))
Find quick answers to common questions about our lessons, pricing, scheduling, and how Exact Science can help your child excel.
Where do you hold your classes?
We hold our classes online or on-site on Saturdays at our branch in Pimlico Academy, London. You can find our timetable here.
What do you need to start learning online?
For lessons you only need a computer or phone with a microphone, camera and Internet access. Wherever you are - in London, Nottingham, New York or Bali - online lessons will be at hand.
When can I take the trial lesson?
You can get acquainted with the school at any time convenient for you. To do this, just leave a request and sign up for a lesson.
What should I expect from the trial lesson?
The trial lesson is a 30-minute online session designed to get a sense of how your child approaches mathematical thinking and problem solving. (In practice, it often runs a bit longer if the student is engaged!)
We typically explore a range of fun and challenging problems drawn from competitions. We adapt the difficulty based on how the student responds, aiming to make it both accessible and stimulating.
After the session, we’ll have a quick conversation with the parent to share observations and suggest a personalised path forward.
I can't attend class, what should I do?
It is OK, it happens! Students have the opportunity to cancel a lesson up to 8 hours before the scheduled time without loss of payment. So you can reschedule it for a convenient time, and the teacher will have the opportunity to
I don't have much free time, will I have time to study?
Learning can take place at your own pace. We will select a convenient schedule and at any time we will help you change the schedule, take a break or adjust the program.
How long is one lesson?
All classes last 1 hour.
Meet our team
Our teachers will tell you how to prepare for exams, help you cope with difficult tasks and win the Olympiad They will tell you about the pitfalls of exams and the most common mistakes, and explain how to avoid them
George Ionitsa
Founder & Maths and Coding Coach
What our students and parents say about learning with us
"Olympiad Maths Lessons helped me a lot to get the Gold medal in Junior Maths Challenge"
St. Paul's Student
"Thanks to the 'Data Science' and 'Coding in Python' lessons I got accepted to my dream university."