求和运算 求s=a+aa+aaa+aaaa+aa..a的值,几个数相加由键盘控制
a = int(input('a='))
n = int(input('n='))
Tn = 0
Sn = []
for count in range(n):
Tn += a
a *= 10
Sn.append(Tn)
print(Tn)
print(f"前{n}个数的和为:{sum(Sn)}")
运算结果:
求和运算 求s=a+aa+aaa+aaaa+aa..a的值,几个数相加由键盘控制
a = int(input('a='))
n = int(input('n='))
Tn = 0
Sn = []
for count in range(n):
Tn += a
a *= 10
Sn.append(Tn)
print(Tn)
print(f"前{n}个数的和为:{sum(Sn)}")
运算结果: