182 + 22 + 222 + 2222 ... Similar

Title: seeking s = a + aa + aaa + aaaa + aa ... the value of a, where a is a number. E.g. 2 + 22 + 222 + 2222 + 22222 (in this case the sum total of the number 5), the number added by several keyboard.

n = eval(input('n = '))
a = input('a = ')
total = 0
for i in range(n):               #int不可迭代 一定要加range
     number = a*(i+1)            #i+1一定要加括号 否则会先×i 再+1
     print(number)
     total += eval(number)
print('total = ',total)


运行结果:
n = 5
a = 3
3
33
333
3333
33333
total =  37035

Published 18 original articles · won praise 0 · Views 148

Guess you like

Origin blog.csdn.net/qq_46399291/article/details/104730135