Lesson 5: Boolean Logic and if
Statements
Topics Covered:
- Understanding
True
andFalse
- Using comparison operators
- Writing simple
if
statements to control program flow
What is Boolean Logic?
Boolean values are either True
or False
. They are used to make decisions in a program.
Comparison Operators
==
equal to!=
not equal to>
greater than<
less than>=
greater than or equal to<=
less than or equal to
print(5 == 5) # True
print(3 > 10) # False
print(7 != 2) # True
Using if
Statements
An if
statement lets you run code only if something is true.
age = int(input("How old are you? "))
if age >= 13:
print("You're a teenager!")
Example: Favorite Animal Checker
animal = input("What is your favorite animal? ")
if animal == "dog":
print("Dogs are awesome!")
Challenge Task
- Ask the user for their test score (0–100).
- If the score is 50 or higher, say “You passed!”.
- Otherwise, say “Try again next time.”
score = int(input("Enter your score: "))
if score >= 50:
print("You passed!")
else:
print("Try again next time.")