您的位置:首页 > 编程语言 > Python开发

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

2015-11-30 15:56 549 查看
#!/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