- Logical operators allow you to combine checks on variables
- The two operators are OR and AND
- OR will be true if either condition is met
- AND will be true when both conditions are met
- In Python, they are always written in lowercase
x = 4
if (x < 1) or (x > 10):
print("x is not between 1 and 100")
if (x > 1) and (x <= 5):
print("x is between 1 and 5")
Tasks
- Type in the code and test that it works
- Modify the program to check if a number entered is between 1-10, 11-20, 21-30, 31-40 or 41-50
- Save and label your code
Extension Task
Modify the program to accept user input, and handle unexpected input appropriately (i.e. the user does not enter a valid number)