Python | Oh boy

/ 12 Jul 2013 /
Ok so this is getting tricky, I'm gonna dedicate a book to python and write all the code so I can practice remembering it, the definition of this code is in the code!



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def main():
    print('This is the clone of an inclusive range function, omg it is so long.')
    for i in inclusive_range(0, 13307, 130):
        print(i, end=' ')

def inclusive_range(*args):
    numargs = len(args)
    if numargs < 1: raise TypeError('requires at least on arg')
    elif numargs == 1:
        stop = args[0]
        start = 0
        step = 1
    elif numargs == 2:
        (start, stop) = args
        step = 1
    elif numargs == 3:
        (start, stop, step) = args
    else: raise TypeError('inclusive_range expected 3 args, but got {}'.format(numargs))
    i = start
    while i <= stop:
        yield i
        i += step

main()
 
Copyright © 2010 M(ath)+me, All rights reserved