← Python for Beginners
0 of 27 lessons done0%

Conditions · Lesson 11 of 27

and, or, not

Combine conditions with:

  • and: true only if both sides are true
  • or: true if at least one side is true
  • not: flips true to false and false to true
age = 20
has_id = True
if age >= 18 and has_id:
    print("Can enter")

day = "Sunday"
if day == "Saturday" or day == "Sunday":
    print("Weekend")

if not has_id:
    print("Bring your ID")

Use brackets to make long conditions clear: (a and b) or c.

Leap year rule

A year is a leap year if it is divisible by 4 and not by 100, or if it is divisible by 400. So 2024 and 2000 are leap years, but 1900 is not.

Your task

Read a year and print Leap year or Not a leap year.