- Related Questions & Answers
- Calculate n + nn + nnn + ? + n(m times) in Python
- Calculate n + nn + nnn + u + n(m times) in Python Program
- Python Program to calculate n+nm+nmm.......+n(m times).
- Python Program to Input a Number n and Compute n+nn+nnn
- Repeating tuples N times in Python
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
- Sum of even numbers from n to m regardless if n<m or n>m JavaScript
- Construct Pushdown automata for L = {0n1m2(n+m) | m,n = 0} in C++
- Construct Pushdown automata for L = {0(n+m)1m2n | m, n = 0} in C++
- Construct Pushdown automata for L = {0m1(n+m)2n | m,n = 0} in C++
- Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Sum of the series 1.2.3 + 2.3.+ … + n(n+1)(n+2) in C
- Python Program to Read a Number n And Print the Series "1+2+…..+n= "
- Construct Turing machine for L = {an bm a(n+m) - n,m≥1} in C++
- Count of numbers satisfying m + sum(m) + sum(sum(m)) = N in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are going to write a program that calculates the following series in Python. Examine the example inputs and outputs for the program that we are going to write.

Input: 34 3 + 33 + 333 + 3333 Output: 3702

Input: 5 5 5 + 55 + 555 + 5555 + 55555 Output: 61725

So, we will have two numbers, and we have to calculate the sum of the series generated as above. Follow the below steps to achieve the output.

1. Initialize the number let's say n and m. 2. Initialize a variable with the value n let's say change. 3. Intialize a variable s to zero. 4. Write a loop which iterates m times. 4.1. Add change to the s. 4.2. Update the value of change to get next number in the series. 5. Print the sum at the end of the program.

You have to create a general formula to generate numbers in the series. Try to get it as your own. If you stuck at the logic, see the code below.

## intializing n and m n, m = 3, 4 ## initializing change variable to n change = n ## initializing sum to 0 s = 0 ## loop for i in range(m): ## adding change to s s += change ## updating the value of change change = change * 10 + n ## printing the s print(s)

If you run the above program, you will get the following output.

3702

Let's see another example with different values as we discussed in the examples.

## intializing n and m n, m = 5, 5 ## initializing change variable to n change = n ## initializing sum to 0 s = 0 ## loop for i in range(m): ## adding change to s s += change ## updating the value of change change = change * 10 + n ## printing the s print(s)

If you run the above program, you will get the following output.

61725

If you have any doubts regarding the tutorial, mention them in the comment section.

Advertisements