Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Practice › Class 9 › Computer Science

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.

Practise this with your AI tutorGo to the questions

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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
Python basicsBoolean logic