fb pixel

Logical operators

In some cases, we would like to check for several conditions at the same time. Imagine we would like to print Great weather in case the temperature is between 20 and 27, as well as there are no clouds. That could be done with an and statement:
if 20 <= temperature <= 27 and clouds == 0:
	print('Great weather')
Python has 3 logical operators:
Logical operator
if a and b:
If both a and b hold
if a or b:
If either a or b hold
if not a:
If a does not hold
In python, they are evaluated with a priority of not first, then and, and then or. So, if the expression has several not, and, and ors, the program would evaluate not operations first, then and operations, and only then will evaluate ors. It’s possible to force other priorities with parentheses.


Given 3 numbers, your task is to find out if any of those is even.
The input contains 3 integers. The program should print Yes if any of the 3 numbers are even and No otherwise.
4 10 5
1 1 3
To check your solution you need to sign in
Sign in to continue