Class 7 · CBSE AI · Strand B — Python for AI
Python loops and conditionals explained for Class 7
How for-loops repeat work and if-statements make choices in Python — including why indentation matters. For Class 7.
Class 7 · CBSE AI · Strand B — Python for AI
How for-loops repeat work and if-statements make choices in Python — including why indentation matters. For Class 7.
Chai making
Making one cup of chai is a set of steps. Making chai for a family of five is a loop — you repeat the same steps for each cup. A conditional is like checking the sugar preference: 'if they want it sweet, add two spoons; else, add none.'
Ticket checker on a train
A ticket checker walks through every compartment (the loop) and for each passenger checks: 'Do they have a valid ticket?' (the conditional). Depending on the answer, they either move on or ask the passenger to pay. Every real job involves this loop-and-check pattern.
Every Dhee Learning session for this concept follows three stages. We share the questions Dhee actually asks, so you can hear what a session sounds like.
Stage 1 — Surface
You have a list of 100 exam scores and want to print only the ones above 90. How many lines of code would that take if you had no loop?
Rote answer
"A for loop repeats code"
Understood
"Without a loop you would write the same check 100 times and the code would break the moment you had 101 scores — a loop lets you write the logic once and apply it to every item automatically"
Stage 2 — Reasoning
What is the difference between a for loop and a while loop? Can you think of a situation where you would prefer a while loop over a for loop?
Follow-up Dhee may use: What is the risk of a while loop that a for loop does not have? What could go wrong?
Stage 3 — Application
Given a list of ten student scores, write code that prints 'Distinction' for scores above 75, 'Pass' for scores between 40 and 75, and 'Needs Support' for below 40. Walk me through your logic before you code it.
Misconception Dhee watches for: Writing if score > 75 and if score > 40 as two separate ifs instead of elif, which causes scores above 75 to also trigger the second condition
Dhee turns this concept into a 15-minute spoken session — asking, listening, and probing — so your child builds the idea themselves.
How for-loops repeat work and if-statements make choices in Python — including why indentation matters. For Class 7.
elif and else are mandatory after an if — in reality, if can stand alone when no alternative action is needed
Dhee opens with a question — for example: "You have a list of 100 exam scores and want to print only the ones above 90. How many lines of code would that take if you had no loop?" — listens to your child's answer, then probes the reasoning behind it. The session ends when the child can apply the idea to a brand-new situation, not just recall it.