Beginner Codes/Python/If Statements
8%

Instructions

If Statements 🤔

Namba daily life-la neraya mudivugal (decisions) edupom la? For example, "Mazhai peidha, kodai eduthutu poven" (If it rains, I will take an umbrella). Programming-layum idhe madhiri decision edukka if statements use aagudhu!

1. How 'if' works under the hood (Ulla enna nadakkudhu?)

Oru if statement eppavume oru kelvi kekum. Andha kelvikku badhil "Yes" (True) illana "No" (False) nu dhaan irukanum.

Condition unmaya (True) irundha mattum dhaan if block-kulla irukka code run aagum. False aaga irundha, Python andha code-a apdiye thandi poidum (Skip pannidum).

score = 90

if score > 80:
    print("Super, neenga pass!")

Inga Python kekura kelvi: "Is 90 greater than 80?". Badhil True. Adhunala, ulla irukka print statement run aagum.

Keezhe irukka Interactive Diagram-a test panni parunga:

Interactive Flowchart

Watch how python thinks!
The Code
score = 90
if score > 80:
print("Super, neenga pass!")
# code continues...
What is happening?
Keela oru test button click pannunga, code epdi run aagudhu nu paapom!
Visualization
> 80 ?
True
False
print()
(Skip code)

2. Real Life Example: Google Pay 💸

Ippa oru GPay transaction example eduthupom. Unga account balance-a vida neenga anuppura amount chinnadha irundha dhaan payment pogum, correct?

balance = 1000
amount_to_send = 500

if balance >= amount_to_send:
    print("Payment Successful! ✅")
    balance = balance - amount_to_send
    print("New Balance:", balance)

print("Have a nice day!")

Try it in your head! Will the payment be successful? Yes, because 1000 is greater than 500!

3. Indentation (Oru step ulla)

Python-la if statement ezhudhum bodhu, adhuku ulla varra code-a oru 'Tab' space (illana 4 spaces) thalli ezhudhanum. Idhuku peru dhaan Indentation.

Idhu Python-ku endha code if block-kulla varum nu puriyavekkum. Space vidalana Python kovichikum (Error varum)!

weather = "rain"

if weather == "rain":
    # Indha code 4 space thalli irukku, so if block-kulla varum
    print("Take an umbrella")
    print("Wear a raincoat")

# Indha code space illama veliya irukku, so eppavum run aagum (Mazhai peidhalum illanalum)
print("Have a safe journey!")

4. Comparison Operators (Oppittu pakradhu)

Conditions create panna namba Comparison Operators use pannuvom:

OperatorMeaning (Artham)Example
==Equal to (Samam)age == 18
!=Not equal to (Samam illa)age != 18
>Greater than (Perisu)score > 50
<Less than (Chinnadu)score < 50
>=Greater than or equal toscore >= 50
<=Less than or equal toscore <= 50

⚠️ Warning! = vs ==: Oru single = vandhu variable-la value store panna use aagum. Double == vandhu rendu values samama nu check panna use aagum. Idhula dhaan neraya paer thappu pannuvanga!

5. Common Mistakes to Avoid (Thavirkka vendiya thavurugal) 🚫

  1. Marandhu poyi colon : vaikama vidradhu: if age > 18 nu potutu colon vaikama vita, SyntaxError varum. Eppavum if line mudiyum idathula : irukkanum!
  2. Indentation thappu: if ku adutha line-a thalli vaikama (space illama) ezhudhina IndentationError varum.

Your Turn! (Unga neram!)

Oru if statement ezhudhunga. Variable age 18 illana adhuku mela irundha, "You can vote" nu print pannanum.

Help

If StatementsExercise 7/7720 XP
❴❵ script.py
python.code
python
Loading...
Terminal
Terminal — python
Beginner Codes Terminal v1.0.0
─────────────────────────────────────
Ready. Click "Run Code" to execute...
Ready
Piston APIPYTHON0 lines