RisingCoder Full course โ†’
Day 1Day 2Day 3Day 4
๐Ÿšฆ
FREE INTERACTIVE NOTES ยท DAY 4 OF 24

Teach the Computer to Choose ๐Ÿšฆ

Green light: go. Red light: stop. Today Bittu learns IF this, do that โ€” the superpower inside every game, app and robot.

1The IF spell

An if checks a truth test. If it's True, the indented lines run. If not โ€” they're skipped, like a door that stays closed:

๐Ÿ
Py: Two sacred rules: end the if line with a : colon, and give the inside lines 4 spaces of indent. That's how Python knows what's "inside" the if.

2if / else โ€” two doors

๐Ÿšช else is the other door: what to do when the test is False.

๐Ÿค–
Bittu: I always walk through exactly ONE door. Test True โ†’ first door. Test False โ†’ else door. Never both.

3elif โ€” a ladder of doors

Need more than two choices? elif (else-if) makes a ladder. Bittu goes down the ladder and stops at the FIRST True:

The Grade Machine ๐ŸŽ“ โ€” slide the marks!

marks = 65
โ†’ took the elif marks >= 60 door: Great! ๐ŸŽ‰

4When Bugly attacks ๐Ÿž

๐Ÿž
Bugly: My two favourite traps! Forget the colonโ€ฆ or mess up the spaces. Watch:
๐Ÿฆ‰
Professor Hoot: SyntaxError = grammar mistake. IndentationError = spacing mistake. Both are fixed in seconds once you can READ them โ€” that's a real programmer skill.

5Decisions + truth tests together

Combine Day 3 and Day 4 โ€” the rollercoaster gate, now automated:

6Quick quiz! ๐Ÿง 

marks = 80. What prints?
if marks >= 75: print("A")  elif marks >= 60: print("B")  else: print("C")
๐Ÿ’ก 80 passes the FIRST test (>= 75), prints A, and the ladder stops there. elif never even looks.
What is missing?
if age >= 10
    print("ok")
๐Ÿ’ก Every if / elif / else line must end with a colon. Python is strict about its punctuation!

7Your mission ๐Ÿš€

Mission 1: Ask for a password with input(). If it's your secret word, print "Welcome!", else print "Intruder alert! ๐Ÿšจ".
Mission 2: Ask for marks and print Topper (90+), Great (60+), Pass (35+) or Try again โ€” with an elif ladder.
Mission 3: Break your code on purpose: remove a colon, read the error, fix it. Bugly hates this trick.

You finished all 4 free days! ๐Ÿ†

Loops, lists, functions, files, APIs and real AI await in Days 5โ€“24 โ€” live classes, recordings, and an instructor who answers your doubts.

See the Full Course โ†’

๐ŸŽฎ Or test yourself in the free Python Arcade โ†’