## Exercise 3.3. (Pythons range function)

**1.**Ensure you have viewed the video (associated with this exercise) at this link >>

**Note:**The Python range function is used extensively within Python programs. I highly recommend that you work through all the examples in this exercise. If you have difficulties with the exercise review the video and take notes on all that is covered and attempt the exercise again.

**2.**Consider the following Python function:

**range(start, stop, [step])**the above is typically what you would see in Python manuals/help/documents. What do you understand by the following i.e. what do they mean in the context of the range function:

a). start

b). stop

c). step

d). the square brackets i.e. []

When using the

*range*function in a Python program would you every expect to see the square brackets appear?

**3.**The range function produces iterables that are arithmetic progressions. In your own words describe what is meant by an iterable in the Python programming language. Also, gives some examples of arithmetic progressions.

**4.**Consider the computer programs below. They are nonsense programs meaning they do not implement any algorithm they are just to test your understanding of relational operators and the

*clause. By reading the program (i.e. do not execute them to get the answers) write down on paper the output you would expect from each program.*

**elif**You can check your own answer by copying the code and pasting it into your Python editor, and then executing the code.

Exercise 3.3 Example 1

Exercise 3.3 Example 2

Exercise 3.3 Example 3

Exercise 3.3 Example 4

Exercise 3.3 Example 5

Exercise 3.3 Example 6

Exercise 3.3 Example 7

Exercise 3.3 Example 8

**5.**Use the Python

**function to populate a Python**

*range***with the following arithmetic progressions. Print each list to the Visual Display Screen to confirm or otherwise your answer.**

*list*[110, 112, 114, 116, 118, 120, 122, 124, 126, 128]

[140, 138, 136, 134, 132, 130, 128, 126, 124, 122]

[-50, -48, -46, -44, -42, -40, -38, -36, -34, -32]

[-20, -17, -14, -11, -8, -5, -2, 1, 4, 7, 10, 13, 16, 19, 22, 25, 28]

[-20, -23, -26, -29]

**END**Next Exercise >>