pythonExample100/JCP018.py

19 lines
392 B
Python
Raw Permalink Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
题目求s=a+aa+aaa+aaaa+aa...a的值其中a是一个数字。例如2+22+222+2222+22222(此时
   共有5个数相加),几个数相加有键盘控制。
1.程序分析:关键是计算出每一项的值。
2.程序源代码:
'''
Tn = 0
Sn = []
n = int(raw_input('n = :\n'))
a = int(raw_input('a = :\n'))
for count in range(n):
Tn = Tn + a
a = a * 10
Sn.append(Tn)
print Tn
Sn = reduce(lambda x,y : x + y,Sn)
print Sn