Friday, 17 April 2026

๐Ÿš€ Day 23/150 – Compound Interest in Python

 

๐Ÿš€ Day 23/150 – Compound Interest in Python

Understanding Compound Interest (CI) is a step ahead of simple interest and is widely used in finance, banking, and investments. It helps you see how money grows over time when interest is applied repeatedly.


๐Ÿ“Œ Formula




Compound Interest=AmountP

Where:

  • P = Principal

  • R = Rate of interest

  • T = Time (years)


๐Ÿ”น Method 1 – Direct Calculation

P = 1000 R = 5 T = 2 Amount = P * (1 + R/100) ** T CI = Amount - P print("Compound Interest:", CI) print("Total Amount:", Amount)





๐Ÿง  Explanation:

  • (1 + R/100) calculates growth rate.

  • ** T means power (compounding over time).

  • Final amount includes interest, so we subtract P to get CI.

๐Ÿ‘‰ Best for: Understanding the formula clearly.


๐Ÿ”น Method 2 – Taking User Input

P = float(input("Enter principal: ")) R = float(input("Enter rate: ")) T = float(input("Enter time (years): ")) Amount = P * (1 + R/100) ** T CI = Amount - P print("Compound Interest:", CI)




๐Ÿง  Explanation:

  • Makes the program dynamic.

  • Converts input into numbers using float().

๐Ÿ‘‰ Best for: Real-life usage.


๐Ÿ”น Method 3 – Using a Function

def compound_interest(p, r, t): amount = p * (1 + r/100) ** t return amount - p print(compound_interest(1000, 5, 2))






๐Ÿง  Explanation:
  • Encapsulates logic inside a function.

  • Easy to reuse anywhere in your program.

๐Ÿ‘‰ Best for: Clean and modular code.


๐Ÿ”น Method 4 – Using Lambda Function

ci = lambda p, r, t: p * (1 + r/100) ** t - p print(ci(1000, 5, 2))



๐Ÿง  Explanation:

  • One-line function using lambda.

  • Great for short calculations.

๐Ÿ‘‰ Best for: Quick operations.


⚡ Key Takeaways

  • Compound interest grows exponentially, unlike simple interest.

  • Use ** for power calculations in Python.

  • Formula: P * (1 + R/100) ** T

  • CI = Amount - Principal


๐Ÿ’ก Pro Tip

Enhance this program by:

  • Adding number of times interest is compounded per year

  • Rounding output using round(value, 2)

  • Building a mini finance calculator combining SI + CI


๐Ÿ”ฅ Final Thought

Compound interest is one of the most powerful concepts in finance — and now you know how to implement it in Python!

Keep building ๐Ÿš€

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (245) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (29) Azure (10) BI (10) Books (262) Bootcamp (6) C (78) C# (12) C++ (83) Course (87) Coursera (300) Cybersecurity (30) data (5) Data Analysis (31) Data Analytics (22) data management (15) Data Science (344) Data Strucures (17) Deep Learning (152) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (19) Finance (10) flask (4) flutter (1) FPL (17) Generative AI (70) Git (10) Google (51) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (42) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (285) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (14) PHP (20) Projects (32) pytho (1) Python (1307) Python Coding Challenge (1128) Python Mistakes (51) Python Quiz (474) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (49) Udemy (18) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)