and and or
Section 3: ConditionsLesson 3.3 · ⏱ 6 min
day = "Friday"
sunny = True
if day == "Friday" and sunny:
print("Let's go to the park!")
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Let's go to the park!

and: both conditions are true. And or: it is enough for one of them to be true.
📌 Another example: in range
and: both conditions together. Is the number between 1 and 10?
When the program asks, we type: 15.
n = int(input("n: "))
if n >= 1 and n <= 10:
print("in range")
else:
print("out of range")
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗n: 15 out of range
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
A holiday: Friday or Saturday (or).
👀 Show the solution🙈 Hide the solution
When the program asks, we type: Friday.
day = input("Day: ")
if day == "Friday" or day == "Saturday":
print("holiday")
else:
print("school day")
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Day: Friday holiday
Result: holiday
Medium
They can play the game if they are 8 or older and have a ticket (yes).
👀 Show the solution🙈 Hide the solution
When the program asks, we type: 9, then no.
age = int(input("Age: "))
ticket = input("Ticket? ")
if age >= 8 and ticket == "yes":
print("enter")
else:
print("sorry")
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Age: 9 Ticket? no sorry
Result: sorry: they are old enough but have no ticket.
Hard
A leap year: divisible by 4 and not by 100, or divisible by 400.
👀 Show the solution🙈 Hide the solution
When the program asks, we type: 2028.
y = int(input("Year: "))
if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:
print("leap year")
else:
print("not leap")
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Year: 2028 leap year
Result: 2028 is a leap year.

