7.4. The Range Function

You can use the range function to create a list of numbers. If the range function is passed just one value it will return a list of all the numbers from 0 to one less than that number.

If two values are passed as input to the range function then it will return a list of values that includes the first value, but ends at one less than the second value. It is inclusive of the first value and exclusive of the second value.

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

Let’s rewrite the program that calculates the product using the range function to generate the list of numbers as shown below.

Note

Discuss topics in this section with classmates.

Show Comments
You have attempted 1 of 7 activities on this page