Skip to content
  • About
  • CoursesExpand
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • BooksExpand
    • Books Authored
  • Patents
Download CV
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

Advance AI PPT

Read More Advance AI PPTContinue

Latest

Prompts for Image Descriptions

Describe the scene using three vivid sensory details — one for sight, one for sound, and one for touch. Summarize the mood of the image…

Read More Prompts for Image DescriptionsContinue

Latest

Dimensionality Reduction

Dimensionality reduction is the process of reducing the number of features (variables) in a dataset while preserving important information. It helps in: ✅ Reducing computational…

Read More Dimensionality ReductionContinue

Artificial Intelligence

Tanh Function in Neural Network

The tanh function, short for hyperbolic tangent function, is another commonly used activation function in neural networks. It maps any real-valued number into a value…

Read More Tanh Function in Neural NetworkContinue

Latest

Why Initialize Weights in Neural Network

Initializing weights and biases is a crucial step in building a neural network. Proper initialization helps ensure that the network converges to a good solution…

Read More Why Initialize Weights in Neural NetworkContinue

Nishant Munjal

Coding Humanity’s Future </>

Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • Write with AI
  • SamplePHP
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2025 - All Rights Reserved

  • About
  • Courses
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • Books
    • Books Authored
  • Patents
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.Ok