LearnFrenzy
Sign in Take a free test

Operators and Expressions · Operators Coding Problems · Question 8

Compound interest with different compounding frequencies in Python Solution, output & explanation

  • Program
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

For ₹1,00,000 at 9% for 5 years, print the final amount when interest is compounded yearly, half-yearly, quarterly and monthly.

Solution
main.py Run
principal, rate, years = 100_000, 9, 5

for label, n in [("Yearly", 1), ("Half-yearly", 2), ("Quarterly", 4), ("Monthly", 12)]:
    amount = principal * (1 + rate / 100 / n) ** (n * years)
    print(f"{label:<12} {amount:>12,.2f}")

Output Verified by running it on Python 3

Yearly         153,862.40
Half-yearly    155,296.94
Quarterly      156,050.92
Monthly        156,568.10

A = P(1 + r/n)^(nt). The :, format spec adds thousands separators.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links