Python: Compute the amount of the debt in n months
Python Basic - 1: Exercise-36 with Solution
Write a Python program to compute the amount of debt in n months. Each month, the loan adds 5% interest to the $100,000 debt and rounds to the nearest 1,000 above.
An integer n (0 ≤ n ≤ 100)
Input number of months: 7
Amount of debt: $144000
def round_n(n): if n%1000: return (1+n//1000)*1000 else: return n def compute_debt(n): if n==0: return 100000 return int(round_n(compute_debt(n-1)*1.05)) print("Input number of months:") result = compute_debt(int(input())) print("Amount of debt: ","$"+str(result).strip())
Input number of months: 7 Amount of debt: $144000
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program which solve the specified equation.
Next: Write a Python program which reads an integer n and find the number of combinations of a,b,c and d (0 ≤ a,b,c,d ≤ 9) where (a + b + c + d) will be equal to n.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join