Python程序来计算n + nm + nmm ....... + n(m次)。
在这里,n是给定的值,它是正数,m是序列运行的次数。我们的任务是计算这个序列。
算法
Step 1: Input n, m; Step 2: Converting the number to string. Step 3: Initializing result as number and string. Step 4: Adding remaining terms. Step 5: Concatenating the string making n, nn, nnn... Step 6: Before adding converting back to integer. Step 7: return sum.
范例程式码
# Python program to sum the series
def sumofseries(n, m):
str1 = str(n)
sum1 = n
sumofstr1 = str(n)
for i in range(1, m):
sumofstr1 = sumofstr1 + str1
sum1 = sum1 + int(sumofstr1)
return sum1
# Driver Code
n = int(input("Enter the value of n"))
m = int(input("Enter the value of m"))
sumofno = sumofseries(n, m)
print("SUM OF SERIES ::>",sumofno)输出结果
Enter the value of n3 Enter the value of m5 SUM OF SERIES ::> 37035
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练