python写一个循环1+到10打印计算步骤的脚本——纯粹无聊玩的
python写一个循环1+到10打印计算
[root@13cml10 ~]# cat a.py
#_*_coding:utf-8_*_
for i in range(0,12):
for a in range(0,i):
print "+",
print a,
print "=",
print sum(range(1,i))
print "\n"
[root@13cml10 ~]# python a.py
= 0
+ 0 = 0
+ 0 + 1 = 1
+ 0 + 1 + 2 = 3
+ 0 + 1 + 2 + 3 = 6
+ 0 + 1 + 2 + 3 + 4 = 10
+ 0 + 1 + 2 + 3 + 4 + 5 = 15
+ 0 + 1 + 2 + 3 + 4 + 5 + 6 = 21
+ 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28
+ 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36
+ 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45
+ 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55
python写一个循环1+到10打印计算步骤的脚本——纯粹无聊玩的
python写一个循环1+到10打印计算
原文:http://blog.51cto.com/legehappy/2044295
来源: http://www.bubuko.com/infodetail-2407380.html