1
Hatchling0 / 300 XP
0day streak 0stars
Your Python practice
Mock tests Readiness
More
Guest mode · saved on this device.

and, or, not

Combine bools into bigger conditions:

  • a and b is True only if both are True
  • a or b is True if at least one is True
  • not a flips True and False
is_weekend = True
has_money = False
go_out = is_weekend and has_money   # False

Parentheses group a choice: (ticket or pass_holder) and not closed requires either credential and an open door.

See it run

lamp_on = True
battery_dead = True
works = lamp_on and not battery_dead
dim = lamp_on or battery_dead
print(works, dim)

Two bools, combined two different ways. Watch how and and or treat the same inputs.

Practice and, or, not

Exercise 1

With temp = 25, sunny = True, raining = False:

  • good_day = temp above 20 and sunny and not raining
  • stay_in = raining or temp below 0

Exercise 2

A museum admits visitors with a ticket or a pass, but never while closed. With ticket = False, pass_holder = True, closed = False, compute boolean admit using or, and and not.

Exercise 3

A download needs Wi-Fi or mobile permission, enough storage, and no pause. Use wifi = False, mobile_allowed = True, free_mb = 500, size_mb = 500, paused = False. Compute boolean can_download; an exact storage fit is allowed.

Free lesson: use the editor to practice it.

Practice

Loading Python…
More
Loading exercise content…
Visualizer Watch your code run line by line

Run your code, then choose Play to follow its execution.

Memory · names → values
Variables appear here as Python creates them.
Output & plots

One-line daily quest