Skip to content
Nishant Munjal
  • About
  • NMRIL Labs
  • Courses
  • ResearchExpand
    • Research Publications
    • Books
    • Patents
    • Ph.D. Supervised
  • Workshop/Conferences
  • ToolsExpand
    • Creative Image Converter
    • Creative QRCode Generator
    • Creative QR Code Generator Tool
    • EMI Calculator
    • SIP Calculator
  • Blog
  • Resume
One Page CV
Nishant Munjal
Python

Compute the Compound Interest.py

Write a function with name compound_interest that takes three arguments: principle, rate and years in order. the rate is float and years is an integer. The function signature should look like the following. This function should return the compounded interest a float value.

def compound_interest(principle, rate, years):
    return comp_interest

How to calculate compounded interest?

The simple interest is calculated as (principle * rate * years) / 100.

If you calculate simple interest on principle every year and add the interest to principle, the result will the principle for next year. This is how you calculate the compounded interest.

Let us take a case of principle = 100, rate = 5 (percent per year) and years = 2 (years) i.e. compound_interest(100, 5, 2):

  • At the end of first year, interest = (100 * 5 * 1) / 100 = 5
  • New priciple for second year = 100 + 5.
  • At the end of second year, interest = (105 * 5 * 1) / 100 = 5.25
  • The total accumulated value: 105 + 5.25 = 110.25
  • The net compounded interest in 2 years is 110.25 – 100 = 10.25
  • Your function compound_interest should return this net compounded interest.
def compound_interest(principle, rate, years):
    i=1
    p=principle
    if years>=1:
        while i<=years:
            d=float((principle*rate*1)/100)
            print(d)
            principle=float(principle+d)
            comp_interest=principle-p
            i=I+1
    else:
        comp_interest=0.00
    return comp_interest

Post navigation

Previous Previous
String Data Type
NextContinue
Churn Email: Day of the Week
  • Latest

    What is CSP Bypass?

    What is CSP Bypass? CSP (Content Security Policy) is a browser security feature that tries to stop attacks like XSS (Cross-Site Scripting) by controlling what…

    Read More What is CSP Bypass?Continue

  • Cybersecurity

    Cybersecurity Tools

    Cybersecurity Tools 1️⃣ Digital Forensics Tools Tool Name Type Used For Who Uses Autopsy Computer forensics Analyze hard disk, recover deleted files Investigators FTK Imager…

    Read More Cybersecurity ToolsContinue

  • Cybersecurity

    Command Injection Attack

    Command Injection Attack A Command Injection attack happens when a web application takes user input and passes it to the system shell (Linux/Windows command line)…

    Read More Command Injection AttackContinue

  • Cybersecurity

    CSRF in DVWA (for learning/demo)

    CSRF in DVWA (for learning/demo) CSRF: An attack where a logged-in user is tricked into sending unwanted requests to a web application, causing actions to…

    Read More CSRF in DVWA (for learning/demo)Continue

  • Cybersecurity

    XSS = Cross-Site Scripting using DVWA

    XSS = Cross-Site Scripting using DVWA It allows an attacker to inject JavaScript into a web page so that it runs in another user’s browser….

    Read More XSS = Cross-Site Scripting using DVWAContinue

Nishant Munjal

Coding Humanity’s Future </>


Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • EMI Calculator
  • Creative QR Code
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2026 Nishant Munjal - All Rights Reserved

  • About
  • NMRIL Labs
  • Courses
  • Research
    • Research Publications
    • Books
    • Patents
    • Ph.D. Supervised
  • Workshop/Conferences
  • Tools
    • Creative Image Converter
    • Creative QRCode Generator
    • Creative QR Code Generator Tool
    • EMI Calculator
    • SIP Calculator
  • Blog
  • Resume
Download CV
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.