Making Decisions
Intro to Python · Lesson 3 of 4
Booleans and comparisons
A bool is either True or False. You get one any time you compare two values:
print(5 > 3) # True
print(5 == 3) # False
print(5 != 3) # True
| Operator | Meaning |
|---|---|
== | equal to |
!= | not equal to |
> / < | greater / less than |
>= / <= | greater/less than or equal to |
Common mistake: = assigns a value, == compares two values. Mixing them up is one of the most common beginner bugs.
if, elif, else
An if statement runs a block of code only when a condition is True. Notice that the indented lines are what "belongs to" the if — Python uses indentation (not curly braces) to group code.
age = int(input("How old are you? "))
if age >= 18:
print("You're an adult.")
elif age >= 13:
print("You're a teenager.")
else:
print("You're a kid.")
Python checks each condition top to bottom and runs the first one that's True, then skips the rest. else catches everything that didn't match.
Combining conditions
Use and, or, and not to combine multiple checks:
age = 16
has_id = True
if age >= 16 and has_id:
print("You can get a driver's permit.")
if age < 13 or age > 19:
print("You're not a teenager.")
and requires both sides to be True; or only needs one.
Try it yourself
Ask the user for a number with input(), convert it to an int, and print "Even" if it's divisible by 2 (hint: use % from Lesson 1) or "Odd" otherwise.
Assignment: Grade Calculator
Write a program that asks the user for a numeric score (0–100) and prints the matching letter grade:
| Score | Grade |
|---|---|
| 90 and above | A |
| 80–89 | B |
| 70–79 | C |
| 60–69 | D |
| below 60 | F |
When you're done, copy your Replit link and submit it below.
