Define a function myRange. This function should behave like Python’s standard
ID: 3535806 • Letter: D
Question
Define a function myRange. This function should behave like Python’s standard range function,
with the required and optional arguments, but should return a list. Do not use the range function
in your implementation! (Hints: Study Python’s help on range to determine the names, positions,
and what to do with your function’s parameters. Use a default value of None for the two optional
parameters. If these parameters both equal None, then the function has been called with just the
stop value. If just the third parameter equals None, then the function has been called with a start
value as well. Thus, the first part of the function’s code establishes what the values of the
parameters are or should be. The rest of the code uses those values to build a list by counting up
or down.)
This is what I have so far, but I cannot seem to make this work. Thank you!
def myRange(start, end, step):
List = []
if start + step <= end-1:
List.append(start)
List += myRange(start + step, end, step)
return List
elif start == end-1:
List.append(end-1)
return List
else: # If start == end,
return List
Explanation / Answer
Here I have stored the 100% executable code. http://www.shrib.com/swzNE3ZM
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.