Loops: practice questions
Class 9 Computer Science. Ten questions with step-by-step answers, for CBSE and ICSE. Try each one before you open its answer.
Key ideas
- for and while.
- These are the multi-step questions examiners like to set. Read each one twice, write down what you know, then plan before you calculate.
- These go beyond the syllabus. Each one has a neat idea that makes it short; brute force is slow.
Read each question twice and say the answer out loud before you check it. For code or binary questions, work it out on paper step by step, the way a computer would.
Ten questions
1.How many times does this run? for i in range(3, 11, 1):
Show the answer
Think: List the values of i.
Work: range stops before the end value.
Answer: 8
2.What does this print? total = 0 for i in range(1, 8): total += i print(total)
Show the answer
Think: Add each i.
Work: 1 + 2 + … + 7.
Answer: 28
3.How many times does this run? for i in range(0, 5, 2):
Show the answer
Think: List the values of i.
Work: range stops before the end value.
Answer: 3
4.What does this print? total = 0 for i in range(1, 6): total += i print(total)
Show the answer
Think: Add each i.
Work: 1 + 2 + … + 5.
Answer: 15
5.How many times does this run? for i in range(4, 8, 1):
Show the answer
Think: List the values of i.
Work: range stops before the end value.
Answer: 4
6.What does this print? total = 0 for i in range(1, 7): total += i print(total)
Show the answer
Think: Add each i.
Work: 1 + 2 + … + 6.
Answer: 21
7.How many times does this run? for i in range(4, 14, 3):
Show the answer
Think: List the values of i.
Work: range stops before the end value.
Answer: 4
8.What does this print? total = 0 for i in range(1, 4): total += i print(total)
Show the answer
Think: Add each i.
Work: 1 + 2 + … + 3.
Answer: 6
9.How many times does this run? for i in range(3, 6, 1):
Show the answer
Think: List the values of i.
Work: range stops before the end value.
Answer: 3
10.What does this print? total = 0 for i in range(1, 5): total += i print(total)
Show the answer
Think: Add each i.
Work: 1 + 2 + … + 4.
Answer: 10
Before you check an answer
- List the values of i.
Questions students ask
- What does Loops in Class 9 Computer Science cover?
- for and while. These are the multi-step questions examiners like to set. Read each one twice, write down what you know, then plan before you calculate. These go beyond the syllabus. Each one has a neat idea that makes it short; brute force is slow.
- How should I practise Loops?
- Read each question twice and say the answer out loud before you check it. For code or binary questions, work it out on paper step by step, the way a computer would. Try all ten questions on this page, then open the chapter in Gradient tuition for step-by-step lessons, a live experiment and an AI tutor who explains where you went wrong.
- Is this for CBSE or ICSE?
- The questions follow the Class 9 Computer Science syllabus shared by CBSE and ICSE / ISC, and suit most state boards too.
Stuck on one of these?
Gradient tuition teaches Loops step by step, with experiments you can play with and an AI tutor who circles the part of the question you missed.
Open Loops in tuition