Tracing loop output: Class 11 practice
range(a, b, k) produces a, a + k, … stopping before b. The quick answer and an example come first; then the method, worked examples and six graded questions.
Tracing loop output: quick answer
range(a, b, k) produces a, a + k, … stopping before b. To predict a loop's result, track the variables in a small table, one row per iteration.
Example: What is printed? total = 0 for i in range(2, 10, 3): total += i print(total) Answer: 15.
- Where it is taught: "Flow of Control", Class 11 Computer Science.
- On this page: the method, 3 worked examples and 6 graded questions with a full answer key.
How to use this page (about 30 minutes)
- Read the method once, then cover the worked examples and try them yourself before reading the steps.
- Do the two Basic questions without notes. If either is wrong, re-read the matching worked example.
- Do the Standard and Challenge questions, then check every line of working against the answer key — not only the final answer.
- Write down the mistake behind each wrong answer and redo that question the next day.
What you should know first
- Variables and assignment
The idea behind tracing loop output
range(a, b, k) produces a, a + k, … stopping before b. To predict a loop's result, track the variables in a small table, one row per iteration.
Step-by-step method
- List the values range() produces.
- Update the variables for each value.
- Write the final value or printed output.
Worked example 1 (Basic)
What is printed? total = 0 for i in range(2, 10, 3): total += i print(total)
- range gives 2, 5, 8
- Sum = 15
- Answer: 15
Worked example 2 (Standard)
How many times is "hi" printed? for i in range(2, 14, 1): if i % 2 == 0: print("hi")
- Values: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
- Even values: 2, 4, 6, 8, 10, 12
- Answer: 6
Worked example 3 (Challenge)
What is printed? f = 1 i = 1 while i <= 7: f = f * i i += 1 print(f)
- Multiplies 1 × 2 × … × 7
- = 5040
- Answer: 5040
Common mistakes and misconceptions
- Including the stop value of range
- Forgetting to update an accumulator
Practice questions
- (Basic) What is printed? total = 0 for i in range(1, 17, 1): total += i print(total)
- (Basic) What is printed? total = 0 for i in range(5, 14, 3): total += i print(total)
- (Standard) How many times is "hi" printed? for i in range(5, 10, 1): if i % 2 == 0: print("hi")
- (Standard) How many times is "hi" printed? for i in range(1, 16, 1): if i % 2 == 0: print("hi")
- (Challenge) What is printed? f = 1 i = 1 while i <= 3: f = f * i i += 1 print(f)
- (Challenge) What is printed? f = 1 i = 1 while i <= 6: f = f * i i += 1 print(f)
Answer key with full working
- Q1: range gives 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 → Sum = 136 → Answer: 136
- Q2: range gives 5, 8, 11 → Sum = 24 → Answer: 24
- Q3: Values: 5, 6, 7, 8, 9 → Even values: 6, 8 → Answer: 2
- Q4: Values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 → Even values: 2, 4, 6, 8, 10, 12, 14 → Answer: 7
- Q5: Multiplies 1 × 2 × … × 3 → = 6 → Answer: 6
- Q6: Multiplies 1 × 2 × … × 6 → = 720 → Answer: 720
Which textbook this practice follows
This skill is taught under "Flow of Control" in Class 11 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.
Still stuck after the answer key?
If the same step in tracing loop output keeps going wrong, a short live 1 on 1 class can find the exact gap. The first demo class is free; send the class, board and chapter on WhatsApp (+91 9379416374).
Related practice and notes
More Class 11 Computer Science practice
Continue with this syllabus
Frequently asked questions
Which chapter is tracing loop output in?
This skill is taught under "Flow of Control" in Class 11 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.
Which question should I start with?
Start with the Basic questions. Move to Standard only when both Basic answers match the key with the same working; the Challenge questions combine this skill with earlier ones.
How were the answers checked?
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.
Is this only for CBSE?
The skill names follow NCERT/CBSE, but the method is the same for ICSE, state boards, IGCSE and IB. Only the chapter name and order differ.
Can I get live help with this topic?
Yes. RG's E-Learning teaches live 1 on 1 online classes; the first demo class is free and fees are shared after it.