KwickAcademy Python · 10 min · free
Decision Making: if, if-else and if-elif-else
Learn decision making in Python: flow of control, if, if-else, if-elif-else, nested if and four exam programs. The if statement runs a block of code only when a condition is True.
Follows the syllabus of: CBSE Class 11 Computer Science (083)
On screen in this lesson
Flow of control
| Sequential: steps run one after another |
| Conditional: choose a path based on a condition |
| Iterative: repeat steps again and again |
Flowchart shapes
| Shape | Used for | Example |
|---|---|---|
| Oval | Start or Stop | Start |
| Parallelogram | Input or Output | Read marks |
| Rectangle | A process | total = a + b |
| Diamond | A decision | marks >= 33? |
Comparing values
| Operator | Asks | Example |
|---|---|---|
| == | equal to? | 33 == 33 True |
| != | not equal to? | 40 != 33 True |
| < and > | less, greater? | 40 > 33 True |
| <= and >= | or equal to? | 33 >= 33 True |
| = | stores a value | marks = 45 |
Colon and indentation
| End the if line with a colon |
| Indent the block, usually by 4 spaces |
| Every line in the block has the same indent |
| No colon gives SyntaxError; no indent gives IndentationError |
How elif is checked
| Conditions are checked from top to bottom |
| The first True condition wins |
| else runs only if all conditions are False |
| else is optional |
Quick recap
| Flow of control: sequential, conditional, iterative |
| if runs a block only when the condition is True |
| if-else gives two paths, if-elif-else gives many |
| Nested if: an if inside another if |
| Colon and indentation are compulsory |
Quick answers
In if-elif-else, which block runs?
The first condition that is True wins, and the rest are skipped.
What does a missing colon give?
SyntaxError.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
Does a program always run top to bottom?42 sec
What does a missing colon give?42 sec
When does the inner if run?42 sec
What does and need?41 sec
What is the pattern?42 secThe full lesson, in text
Aarav, Ma'am gave us a marks card program. Type marks, and it says Pass or Fail.
Easy one. Pass mark is thirty three, na? What did you test?
My unit test marks, forty five. So it should only say Pass.
Run it. Let's see.
Look! It says Pass, and then Fail too! How can one student pass and fail together?
If a real marks card said both, the whole class would laugh!
Achha, the Fail line starts at the left edge. Maybe that matters?
But why does it still run? And how do we fix it?
Honestly, not sure. Let's ask Kajal Ma'am before the practical.
Good question, Riya. Welcome to Kwickprep. Today we learn how Python makes decisions.
Flow of control means the order in which the lines of a program run. In sequential flow, lines run one after another. In conditional flow, the program checks a condition and chooses a path. In iterative flow, it repeats steps, which we learn later.
A flowchart draws the flow of control with boxes and arrows. An oval shows start or stop. A parallelogram shows input or output. A rectangle shows a process. A diamond shows a decision, with yes and no arrows.
A condition is a question with a True or False answer. Double equals asks, are two values equal? Not equal to asks, are they different? Less than and greater than compare sizes. The or equal to versions also say yes for equal values. One equals sign stores a value. Memory hook: one equals stores, two equals compares.
So can we write if marks equals thirty three with one equals sign?
No, Riya. With one equals sign, Python gives a syntax error. To compare, always use double equals.
Here is a conditional flow as a flowchart. We read the marks. The diamond asks, marks thirty three or more? If yes, print Pass. If no, the flow goes down to print Fail. Then stop.
For more paths, we draw diamonds in a row. We read the marks. First, marks seventy five or more? If yes, Grade A. If no, marks fifty or more? If yes, Grade B. Otherwise, Grade C.
The if statement runs a block only when its condition is True. Marks is forty five, and the line says, if marks greater than or equal to thirty three, colon. True, so it prints You passed. The last line is not inside the if, so it always runs.
So that is why the Fail line ran every time?
Exactly, Aarav. A line outside the if does not care about the condition.
The if line ends with a colon. The block under it is indented, pushed right, usually by four spaces. Every line in a block has the same indent. No colon gives a syntax error, and no indent gives an indentation error. Exam tip: always name the exact error in your answer.
For two paths, yes and no, we use if else. The wallet has one hundred fifty rupees, and the recharge plan costs one hundred ninety nine. Is balance at least the plan? No. So Python skips the if block and prints Add money first.
For more paths, use elif, short for else if. The age is eight. Less than five? No. So Python checks the elif. Less than twelve? Yes, so it prints Half ticket.
So if age was three, would it print Free ticket and Half ticket both?
No, only Free ticket. Only one block of an if elif else chain ever runs.
Four rules about elif. Conditions are checked from top to bottom. The first True condition wins, and the rest are skipped. The else runs only if every condition above is False. And else is optional, so you can leave it out. Memory hook: first True wins, the rest are skipped.
A nested if is an if inside another if. The inner question is asked only when the outer answer is yes. Has ticket is already True, so we do not need to write double equals True. Then age sixty five is sixty or more, so it prints Senior seat. Notice the inner block has two levels of indent.
Now four exam programs. First, absolute value, which is the distance from zero, so it is never negative. The number is minus seven, which is less than zero, so we make it minus number. Minus of minus seven is seven. Python also has a ready function, abs, but exams want you to write it with if.
Second, who scored the most? Riya has forty five, Aman seventy two, and Neha sixty. The word and means both conditions must be True. Is Riya bigger than both? No. So we only compare Aman and Neha. Aman is greater than or equal to Neha, so it prints Aman.
Third, divisibility. The percent sign is the modulus operator, which gives the remainder after division. If the remainder is zero, the number divides exactly. Eighty four divided by seven is twelve, remainder zero, so it prints Divisible by seven.
Fourth, grades. Sixty eight is not seventy five or more, but it is fifty or more, so Grade B. Pause and predict. What prints if marks is exactly seventy five?
Grade B, because seventy five is not more than seventy five?
Careful, Riya. Greater than or equal to includes seventy five, so it prints Grade A. Exam tip: output questions love edge values like exactly seventy five.
A conditional expression is a short, one line if else. Res, short for result, is Pass if marks is at least thirty three, else Fail. Marks is forty, so res becomes Pass.
Match case needs Python three point ten or newer. It compares one value with several choices, each written after the word case. Here the coach is S L, so it prints Sleeper. The underscore case catches any other value, like otherwise.
Some exams want pseudocode. Same idea: if, then, else, and end if.
Got it! Fail was outside the if, so it always ran. Now it sits under else.
Okay, test it properly now. Run it with forty five again.
Only Pass! And with twenty, only Fail. One path each time.
And exactly thirty three? Pass, because greater than or equal to includes it.
Nice, yaar. Like a cricket umpire. Out or not out, never both at once.
And the colon and indent are right too. Checked them first this time.
Let us revise. Flow of control is sequential, conditional or iterative. An if runs only when its condition is True. If else gives two paths, if elif else gives many. A nested if sits inside another if. And never forget the colon and indentation.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 9 Information Technology (402) | Digital Presentation |
| CBSE Class 9 Artificial Intelligence (417) | Part B - Unit 5: Introduction to Python |
| CBSE Class 11 Computer Science (083) | Computational Thinking and Programming - I |
| CBSE Class 11 Computer Science Essentials (083) | Computational Thinking and Programming - I |
| CBSE Class 11 Informatics Practices (065) | Introduction to Python |
| CBSE Class 11 Artificial Intelligence (843) | Python Programming |
| Cambridge IGCSE Grade 9 Computer Science (0478) | 8. Programming |
| Cambridge IGCSE Grade 10 Computer Science (0478) | 8. Programming |
| Edexcel GCSE GCSE Computer Science (1CP2) | Topic 6: Problem solving with programming |
| Programming All levels Python | Control Flow |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

