


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Selection allows a program to decide based on a condition. Example 1: age = 20 if age >= 18 : print("Adult") else: print("Under 18") Think: If something is true, do this. Otherwise, do that.
A condition produces either True or False. Common comparison operators: Operator Meaning Example == Equal to x == 10 != Not equal x != 10 > Greater than x > 10 < Less than x < 10 >= Greater/equal x >= 10 <= Less/equal x <= 10
mark = 65 print(mark >= 40 ) Output: True
Used when something should happen only if a condition is true. Example 3: temperature = 30 if temperature > 25 : print("It's hot")
Used when there are two possible outcomes. Example 4: mark = 35 if mark >= 40 : print("Pass") else: print("Fail") Output: Fail
Use elif when there are more than two possible outcomes.
A student passes with 40 or more. Input: mark Condition: mark >= 40 True → Pass False → Fail
Always test values around the boundary. If 40 is a pass: Mark Expected 39 Fail 40 Pass 41 Pass This helps find errors in conditions.
Selection = decision-making. Conditions produce True or False. if → one decision. if/else → two outcomes. elif → multiple outcomes. and, or, not → combine conditions. Condition order matters. Always test boundary values.