 At the end of the last video, we were left with the question of how to use a for loop if we didn't know in advance how many times we would be repeating that loop. The answer to that question is the range function, which effectively produces a list of integers. Here's a program that uses the simplest form of range. For I, in range 5, print I. In this case, my loop variable is just the single letter I rather than a word like counter. This is a convention among Python programmers. Common loop variables will be letters like I, J, K, or N. When we get to the discussion of lists, we'll see why this is a reasonable choice. Let's run the program and see what it produces. We see that it produces the numbers 0, 1, 2, 3, and 4. That means we did loop through 5 times. So range 5 is the same as if we had typed the list 0, 1, 2, 3, 4. When you have a simple range, the loop variable starts at 0 and goes up to, but not including, the number you specified. Why start with 0? Because if you're doing calculations with the loop variable, those calculations are almost always easier when you start at 0 than when you start at 1. Trust me on this. This simple form of range is exactly what we need to solve the problem of allowing the user to specify the number of sides they want for a polygon. Let me move the shell down a bit here and clear it out. Here's a program with the turtle initialization already done for us. I'll ask the user for the number of sides they want for the polygon. N sides is assigned the int of input of how many sides. And I'll also ask how long they want each side to be. Side length refers to the int of input of how many pixels per side. And then I need to calculate the angle that I'm going to turn when drawing the polygon. And that angle is assigned 360 divided by the number of sides. Now I'm ready for the loop. This time I'm going to use a more descriptive loop counter for side in range and sides. I'm going to go forward the specified length. And this time I'm going to turn right by the angle that we've calculated. Let's run the program and see how it works. Let's say I want a five-sided polygon at 100 pixels per side and I get a large pentagon. Let's run it again and say I want 12 sides of length 37. And I get a 12-sided figure. Let's give it one more run and say I want a six-sided figure with 120 pixels per side. And I get a giant hexagon. So the program is working just great. The next version of the range function comes in handy when you need to have a starting point other than zero. This will solve the problem of displaying the table of numbers in their cubes, where we let the user specify the beginning and ending number. Here's what this form of range looks like in the shell. For I in range 5, 9, print I. In this version of range, you specify the beginning and ending number. This example is the equivalent of writing the list 5, 6, 7, and 8. As with the simple range, the numbers that it produces go up to but not including the ending number. Here's the start of our program that does the table of cubes. Here's the start of the program that displays the numbers in their cubes. First, let's ask the user for the starting and ending numbers they want. Start refers to the int of input of starting number. And finish is assigned the int of input of ending number. Once I have the starting and ending number, I can print my heading. And then I can say for I in range start to finish plus 1. I have to add 1 because I want the finish number to be included. And remember, range goes up to but not including the number I specified. And now I do my formatted print to 6 space numbers, integers. And I fill in those formats with I and I cubed. Let's clear the shell and run the program. My starting number will be, let's say 21, ending number 26. And there's the cubes of the numbers 21 through 26. Run it again. My starting number, let's say, is 45 through 56. And there are the cubes of the numbers 45 through 56. There's a third version of range that lets you specify the starting number, ending number, and step size between numbers. I'll show you that here in the shell. I can say for I in range 2 to 11 in steps of 3, print I. And this is prints 2, then 2 plus 3, which is 5, then steps 3 further, which is 8. 3 further would be 11, but remember I never include the final number, so this prints out 2, 5, and 8. I don't have a good example of a program that uses this version of range, but I do want you to know about it so that you can use it if you ever do need it. And that's range, the function that effectively produces lists of integers that you can use in a for loop when you don't know in advance how many times you need to loop.