-5

Is there a function in python that lets me input a number (i.e 3) and a beginning and end number and steps accordingly:

function (10, 21, 2) -> [15, 20]

function (0, 16, 5) -> [3, 6, 9, 12, 15]

jamylak
  • 120,885
  • 29
  • 225
  • 225
Jamie
  • 89
  • 1
  • 8

3 Answers3

1

Range is the function which does the same :

for a in range(0,16,3):
    print a 

Better follow some tutorials these are very basics of python .

jamylak
  • 120,885
  • 29
  • 225
  • 225
coder3521
  • 2,482
  • 1
  • 25
  • 44
0

If you want to use in a for loop you want - range(<start>,<end>,<Step>)

Anand S Kumar
  • 82,977
  • 18
  • 174
  • 164
0

You can accomplish your task using the range fucntion. The base syntax is:

range(start, end, step)
range(1, 10, 2) = [1, 3, 5, 7, 9]
range(1, 10, 5) = [1, 6]

More info: http://www.pythoncentral.io/pythons-range-function-explained/

FBidu
  • 942
  • 8
  • 19