Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
21 lines (17 loc) · 514 Bytes

File metadata and controls

21 lines (17 loc) · 514 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding:utf-8 -*-
__author__ = 'gjw'
__time__ = '2018/1/5 0005 下午 4:13'
# 题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加由键盘控制
# 程序分析:关键是计算出每一项的值。
from functools import reduce
T = 0
s = []
n = int(input('n='))
a = int(input('a='))
for count in range(n):
T += a
a *= 10
s.append(T)
print(T)
s = reduce(lambda x, y: x+y, s)
print("计算总和为:", s)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.