-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
  • 128,818
  • 30
  • 231
  • 230
Jamie
  • 109
  • 1
  • 9

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
  • 128,818
  • 30
  • 231
  • 230
coder3521
  • 2,608
  • 1
  • 28
  • 50
0

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

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
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
  • 972
  • 9
  • 21