给定不超过9的正整数a,给定正整数n,n是偶数,4<=n<=18,要求编写程序
给定不超过9的正整数a,给定正整数n,n是偶数,4<=n<=18,要求编写程序求aa+aaaa+aaaaaa++aaa(n个a)之和。 如果 我没理解错的话 n 是 a 的个数def cou(a,n):
## print(f"a = {a},n = {n}")
tem = a
for i in range(1,n,1):
tem = tem*10
tem += a
## print(tem)
return tem
a = int(input("输入一个不大于9 的正整数:"))
count = 0
for n in range(4,20,2):
count += cou(a,n)
print(f"count = {count}")
a = int(input("输入一个不大于9 的正整数:"))
sum = 0
for i in range(4,20,2):
b = str(a)*i
sum += int(b)
print(sum)
#coding:gbk
a = int(input('输入一个 1~9 范围内的整数 : '))
if a > 0 and a < 10 :
n = int(input('输入一个4~18 范围内的偶数 : '))
if n > 3 and n < 19 and not n % 2:
sum = 0
for i in range(2 , n + 1 , 2):
d = 0
for j in range(i):
d = d * 10 + a
sum += d
print(sum)
else:
print('输入无效-2!')
else:
print('输入无效-1!') def f(a, n):
return (100 * (10**n - 1)//99 - n//2) // 9 num = int(input("輸入一個不大於 9 的正整數:"))
print(sum())
页:
[1]