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
Experiments › Computer Science

Loop builder

Set where a loop starts, where it stops and how much it steps by, and watch it run. Loops repeat work so the computer does it for you.

Make the loop print exactly: 0, 2, 4, 6
for i in range(0, 5, 1): print(i)01234

Prints: 0, 1, 2, 3, 4

Change the controls until it fits.

What to notice

  • range(start, stop, step) stops before it reaches stop.
  • A step of 2 visits every other number.
  • A negative step counts down.

Challenges

  1. Make the loop print exactly the target numbers.
  2. Make it run exactly 5 times.
  3. Count down from 10 to 1.

Lessons that use it

  • Class 7: Algorithms and flowcharts
  • Class 9: Loops
  • Class 11: Python programming