DAY 5

Conditions ⚡🤔🚦

Code can make decisions using if statements. Programs evaluate TRUE/FALSE conditions and choose what to do. This is how apps respond differently to different situations.

⏱ 30 mins
⚡ +50 XP
Conditions ⚡🤔🚦

Day 5: Conditions — Programs That Make Decisions!

What's a Condition?

Think of a traffic light. Green means GO, red means STOP. Your code works the same way — if something is true, do this. If not, do that. That's a condition!

Your First if Statement


age = 21

if age >= 18:
    print("You can vote!")

Is age >= 18? Yes! So "You can vote!" prints. If age was 15, nothing prints. The code decides!

if and else Together


score = 45

if score >= 50:
    print("You passed!")
else:
    print("You failed!")

if runs when TRUE. else runs when FALSE. One or the other — never both!

Multiple Choices with elif


score = 85

if score >= 90:
    print("Grade A!")
elif score >= 70:
    print("Grade B!")
else:
    print("Grade C!")

elif means "else if". Check many conditions in order. First one that's TRUE wins!

Real World Connection

Netflix checks if you're 18+ before showing adult content — that's an if statement! Swiggy checks if your cart total is over 199 for free delivery — if statement! Every decision every app makes is an if/elif/else!

Common Mistakes

Missing the colon — Python will break!


if age >= 18     # WRONG — missing :
if age >= 18:    # CORRECT

Using = instead of == to compare.


if name = "Rohith":   # WRONG — = stores, == compares!
if name == "Rohith":  # CORRECT

Forgetting indentation — code inside if must have spaces!

Mini Challenge

Mini Challenge

Ask the user their age. If they're 18 or older print "You can drive!". If they're under 18 print "Too young!". Run it and try different ages!

Quick Quiz

Q: What symbol checks if two things are equal? A: == not =!

Q: What runs when the if is FALSE? A: else!

Q: What do you put at the end of every if line? A: A colon :

Key Takeaways

Key Takeaways

  • if checks a condition — TRUE runs the code, FALSE skips it.
  • else runs when the if is FALSE.
  • elif checks another condition in between.
  • Always use == to compare, not =.
  • Always add : after if/elif/else and indent the code inside.

← Previous Lesson