In Python, Implementing Own Range() To Return List

def myRange(start, stop = None, step = None):
    nums = None
    if None == step:
        step = 1
    if None == stop:
        stop = start
        start = 0
    if None != start and None != step:
        nums = []
        while start < stop:
            nums.append(start)
            start += step
    return nums

if '__main__' == __name__:
    print(myRange(3))
    print(myRange(1, 7))
    print(myRange(1, 7, 2))
    print(myRange(-5, 1))
    print(myRange(-5, 1, 2))
Download

Comments

Popular posts from this blog