انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Python: home
0. Lab tour1
1. The start5
2. Variables and input5
3. Conditions5
4. Loops5
5. Lists4
6. Functions4
7. Drawing with the turtle3
8. The project: the guess-the-number game3
9. Strings in depth1
10. Dictionaries (dict)3
11. Randomness and errors3
12. Classes and objects (class)2
13. Pro drawing and charts3
14. The final project: the quiz game2

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:
Let's go to the park!
🐍 Open the code in Robo Python ↗
The example in Robo Python: the code on the right and what appeared on the left
The example in Robo Python: the code on the right and what appeared on the left

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.

🐍 In range
n = int(input("n: "))
if n >= 1 and n <= 10:
    print("in range")
else:
    print("out of range")
🖥️ The output in Robo Python:
n: 15
out of range
🐍 Open the code in Robo Python ↗
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

A holiday: Friday or Saturday (or).

👀 Show the solution

When the program asks, we type: Friday.

🐍 Solution
day = input("Day: ")
if day == "Friday" or day == "Saturday":
    print("holiday")
else:
    print("school day")
🖥️ The output in Robo Python:
Day: Friday
holiday
🐍 Open the code in Robo Python ↗

Result: holiday

Medium

They can play the game if they are 8 or older and have a ticket (yes).

👀 Show the solution

When the program asks, we type: 9, then no.

🐍 Solution
age = int(input("Age: "))
ticket = input("Ticket? ")
if age >= 8 and ticket == "yes":
    print("enter")
else:
    print("sorry")
🖥️ The output in Robo Python:
Age: 9
Ticket? no
sorry
🐍 Open the code in Robo Python ↗

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

When the program asks, we type: 2028.

🐍 Solution
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:
Year: 2028
leap year
🐍 Open the code in Robo Python ↗

Result: 2028 is a leap year.

Finished the lesson? Mark it so your progress counts.