Computer Science, asked by pauldeepanjan806, 5 days ago

Q.4) Use the Python range() function to create the following list:[7,3,-1,-5]​

Answers

Answered by anindyaadhikari13
2

Answer:

The given co‎de is written in Python.

a = list(range(7, -5-1, -4))

print('Required list is:', a)

Explanation:

We can notice that the list starts with number 7. So, the first parameter in the range function should be 7.

Now, the list ends with -5. So, the second parameter will be -6. The last number -5 will be is excluded. To avoid that, we will write -6 in place of -5.

Now, each number is obtained by adding -4 to previous term. So, the third parameter will be -4.

So, the range function will look like: range(7, -6, -4)

It is then converted to list.

General Syntax of range function:

> range(start, stop, increment_value)

The parameters start and increment_value are option. If we don't write start value and increment_value, they are assumed to be 0 and 1 respectively.

Output:

Required list is: [7, 3, -1, -5]

Refer to the attachment.

Attachments:
Similar questions