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.

Before you keep reading...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

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.

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