๐ก Interactive lessons ยท free, no sign-up
For loops, and what range() really gives
Play Python For Loops and range()
Loading Python For Loops and range()โฆ
How to play Python For Loops and range()
- Read the first step: range makes the numbers a loop goes through.
- Move the sliders and switches to change the diagram and watch what happens. The readout under the picture shows the numbers.
- Answer each question. If you are wrong you get a hint and can try again, with no penalty.
- Some steps ask you to make something happen, such as hitting a target value. Experiment until it works.
- Finish the lesson to earn XP and see how many questions you got right first time.
Tips and strategy
- Do not rush. The controls are there to be played with, so try extreme values as well as sensible ones.
- Say what you notice out loud or write it down before you press Continue.
- Use the hint when you are stuck, and then try to explain the answer in your own words.
- Write out the first few numbers by hand, then ask where the loop stops.
Keep playing
More games you might like
Coding games ยท Ages 9+NewPython Practice LabWrite real beginner Python, run it in the browser and solve small challenges.
Pythonvariables
Play
Coding games ยท Ages 7+NewCode the RobotPlan a short command sequence to guide a robot through a grid maze.
sequencedebugging
Play
Interactive lessons ยท Ages 10+NewPython Lists and IndexesPick items from a list by index, including negative indexes and IndexError.
Pythonlists
Play
Coding games ยท Ages 8+NewTurtle StudioWrite movement commands and watch a turtle draw shapes on a canvas.
loopsangles
Play
FAQ
Python For Loops and range(): questions
What does range(1, 6) give?
The numbers 1, 2, 3, 4, 5. It starts at 1 and stops before 6.
Why is the stop value not included?
range counts how many steps to take from the start, and it stops before reaching stop. This makes range(n) give exactly n numbers starting from 0.
What does the step do?
It sets how much to add each time. range(0, 10, 2) goes up in twos.
What age is this lesson for?
It suits ages 10 to 16 as a first step in Python loops.
Start a conversation
Questions about classes?
A parent or guardian can share the learner's age, level and goals, and we'll suggest a starting point and confirm the format before anything is booked.
- Tell us the learnerโs age or grade and goals
- Weโll suggest a suitable class or learning path
- Weโll confirm format, timing and fees with a parent or guardian