Syncing account progress…

Back

Beginner · 10 min

Combining conditions

Use and, or, and not to combine simple checks.

Require both conditions

and is true when both Boolean conditions are true. Use it when two requirements must be met together.

age = 20
tickets = 1
print(age >= 18 and tickets > 0)

Output

True

Allow either condition

or is true when at least one Boolean condition is true. not reverses a Boolean value. These examples combine comparisons and Boolean values.

day = "Sunday"
print(day == "Saturday" or day == "Sunday")
print(not (day == "Sunday"))

Output

True
False

Combining conditions

  1. Evaluate each comparison before combining them.
  2. Try changing one condition while keeping the other fixed.

Try it yourself

Code runs on this device. When you are signed in, drafts sync to your account.

Check a booking

Keep age as 22 and seats as 2. Display whether the age is at least 18 and there is at least one seat.

Practice