python - newby needs guidance with what is probably a simple function -
i'm struggling write function pass following doctests. can't find way make third argument in parameter optional:
write whole function definition make_numberlist including function header , body doctests pass
def make_numberlist(): """ return list of numbers first last exclusive optional step. >>> make_numberlist(3,9,2) [3, 5, 7] >>> make_numberlist(-3,2) [-3, -2, -1, 0, 1] >>> make_numberlist(5,1,-1) [5, 4, 3, 2] """ return range (r1, r2, step)
you need give function arguments:
def make_numberlist(r1, r2, step=1): return range(r1, r2, step)
r1
, r2
required arguments, step
optional , has default value of 1
.
you do:
make_numberlist = range
if you're using python 3 (which are), range
doesn't return list, take consideration.
Comments
Post a Comment