Lesson 06 � Logic
CODE KO
DECISION DO.
Real program har input par same response nahi deta. User logged in ho to dashboard, nahi ho to sign-in. Score pass ho to certificate. Isi branching ko if, elif aur else
WHY: business rules ko code mein badalna
Condition ek expression hai jo True ya False banata hai. Python true branch ko run karega, false case mein next branch check karega.
score = 76
if score >= 90:
print("Excellent")
elif score >= 60:
print("Pass")
else:
print("Practice more")Sabse pehle rule ko test karta hai.
Pehla rule false ho to alternate rule test karta hai.
Koi condition match na ho to fallback path.
Comparison ko correct padho
== equality compare karta hai; = value assign karta hai. >=, <=, != bhi commonly use hote hain. Conditions ko top-to-bottom order mein likho: more specific cases pehle aate hain.
Multiple rules: and / or / not
and tab true hai jab dono conditions true hain. or mein ek true condition kaafi hai. Parentheses use karo jab intent clear karna ho; readable condition clever short condition se better hai.
Quick check
score variable pass hai ya nahi check karne wali condition likho. Pass mark 60 hai.
Greater-than-or-equal operator chahiye, assignment operator nahi.
Common mistakes
if score = 60:invalid hai; comparison ke liye==.- Colon
:aur indentation bhoolna block syntax ko break karta hai. - Broad condition pehle likhoge to specific
elifkabhi reach nahi hoga.
Ab same logic ko multiple values ke liye repeat karna seekho.