)求 s= ataa+aaa+··· …+aaa'a的值,其中a是一个数字,如2+22+222+2222,a的值和加数个数n, 均从键盘狭取。要求a属于[1,9].n2小于10(如果不满足此条件,就重新输入) 输入:输入a值和n值 输入提示信息:”Please 输入格式:“sd” input a: 输入提示信息:输入格式:“%d”如: "Please input n: Please input a:8 Please input n:9输出:算式及和输出提示信息: ”Sum-算式“,输出格式”%1d“”Sum-和,输出格式”%1d“如: Sum-8+88+888+8888+88888+888888+8888888 Sum=987654312
时间: 2023-12-14 17:38:45 浏览: 171
论文研究-A Resource Allocation Scheme with Multiple Relays Aided in Downlink OFDMA Systems.pdf
以下是求解 s = a taa + aaa + ... + aaa'a 的值的 Python 代码:
```python
a = int(input("Please input a: "))
n = int(input("Please input n: "))
while n ** 2 >= 10:
print("n^2 should be less than 10, please re-enter.")
n = int(input("Please input n: "))
s = 0
t = 0
for i in range(n):
t = t * 10 + a
s += t
print("Sum-", end="")
for i in range(n):
if i != n-1:
print(str(a)*(i+1) + "+", end="")
else:
print(str(a)*(i+1), end="")
print("")
print("Sum=%d" % s)
```
运行示例:
```
Please input a: 8
Please input n: 9
Sum-8+88+888+8888+88888+888888+8888888+88888888+888888888
Sum=987654312
```
阅读全文