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 the debt in n months. The borrowing amount is $100,000 and the loan adds 5% interest of the debt and rounds it to the nearest 1,000 above month by month.

An integer n (0 ≤ n ≤ 100).

Sample Solution:

Python Code:

def round_n(n):
    if n%1000:
        return (1+n//1000)*1000
        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())

Sample Output:

Input number of months:
Amount of debt:  $144000


Flowchart: Python - Compute the amount of the debt in n months

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 Python skills with w3resource's quiz

Python: Tips of the Day

Returns the symmetric difference between two lists, after applying the provided function to each list element of both


def tips_symmetric_difference_by(p, q, fn):
  _p, _q = set(map(fn, p)), set(map(fn, q))
  return [item for item in p if fn(item) not in _q] + [item for item in q if fn(item) not in _p]
from math import floor
print(tips_symmetric_difference_by([4.2, 2.4], [4.6, 6.8],floor))


[2.4, 6.8]