Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Show the even numbers from to with a loop and a step.
range(start, stop, step): the stop value is not included.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. The first number is 2, and the step is 2. The stop must be after 20, so it is 21.
range(2, 21, 2) makes 2, 4, 6, 8, 10, 12, 14, 16, 18, 20. That is ten numbers.
Check. If you wrote range(2, 20, 2), the last number would be 18, because 20 is not included.
Log in to join the discussion.
Loading…