python循环求值

 

 

python循环输出1+11+111+1111+11111=12345

def test(n):
	sum=0
	for i in range(1,n+1):
		while i>0:
			sum+=10**(i-1)
			i-=1

	return sum

print(test(5))

 

posted @ 2020-08-01 00:00  feiyueNotes  阅读(338)  评论(0)    收藏  举报