递增递减显示数字列表1-10

#!/usr/bin/env python

def increase(start, stop):
    print '#' * 20
    lt = range(start, stop)
    length = len(lt)
    i = -(length - 1)

    while i <= -1:
        lt = range(start, stop)
        lt = lt[0:i]
        for n in lt:
            print n,
        print '\n',
        i += 1   
    
    lt = range(start, stop)
    for n in lt:
        print n,
    print '\n',

def deciline(start, stop):
    print '#' * 20
    lt = range(start, stop)

    for n in lt:
        print n,
    print '\n',

    i = -1
    length = len(lt)

    while i >= -length:
        lt = range(start, stop)
        lt = lt[:i]
        for n in lt:
            print n,
        if i == -(length - 1):
            pass
        else:
            print '\n',
        i += -1   

if __name__ == "__main__":
    increase(1,11)
    deciline(1,11)

运行结果如下(先递增后递减):

####################

1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9 10 
####################
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 

你可能感兴趣的:(python)