Range FunctionΒΆ

  1. Replace <1> in the following code with a call to range() so that the for loop prints out all integers from 1 to 10, inclusive.
    The range function takes 1, 2, or 3 integer parameters. The parameters are range(start=0, stop, step=1). If a start value is not provided, the value 0 is used. If a step value is not provided, the value 1 is used. The stop value indicates the upper limit that the result should be less than. E.g., if stop is 10, then the result of the range call will end at 9.
  1. Replace <1> in the following code with a call to range() so that the for loop prints out all integers from 0 to 99, inclusive.
    Remember that you can omit the first parameter if you want the result to start at 0.
  1. Replace <1> in the following code with a call to range() so that the for loop prints out all integers from -10 to 10, inclusive.
    Parameters can be negative, and if step is one, the results will increase by 1 each time through the loop.
  1. Replace <1> in the following code with a call to range() so that the for loop prints out all even integers from 0 to 100, inclusive.
    Parameters can be negative, and if step is 1, the results will increase by 1 each time through the loop.
  1. Replace <1> in the following code with a call to range() so that the for loop prints out all multiples of 5 from 0 to 200, inclusive.
    Go back and review previous questions if you need a hint.
  1. Replace <1> in the following code with a call to range() so that the for loop prints out all integers from 10 down to 1, inclusive.

    Provide a step of -1.

    range() produces values down to but not equal to or less than the stop value, if the step is negative.

Next Section - For Loops