- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to calculate n+nm+nmm.......+n(m times).
Here n is given value which is positive number m is the number of times till which the series run. Our task is to calculate this series.
Algorithm
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.
Example Code
# 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)
Output
Enter the value of n3 Enter the value of m5 SUM OF SERIES ::> 37035
Advertisements