List

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

Leave a Reply

Your email address will not be published. Required fields are marked *

  Posts

1 2 3
November 2nd, 2020

Churn Emails – Count Number Domain

Write a function count_message_from_domain which reads the file /cxldata/datasets/project/mbox-short.txt. This function builds a histogram using a dictionary to count how many messages have […]

November 2nd, 2020

Churn Emails – Count Number of Messages

Python Project – Churn Emails – Count Number of Messages From Each Email Address Write a function count_message_from_email which reads the file /datasets/project/mbox-short.txt.  […]

November 2nd, 2020

Churn Email: Day of the Week

Python Project – Churn Emails – Find Which Day of the Week the Email was sent Write a function find_email_sent_days which reads […]

October 20th, 2020

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 […]

October 18th, 2020

String Data Type

A string is a sequence of characters. String Data Type str1=”hello” print(type(str1)) Ans: <class ‘str’> str2=’123′ print(type(str2)) Ans: <class ‘str’> […]

October 18th, 2020

String Library

String Replace str=”Hello Bob” print(str) rstr=str.replace(‘Bob’, ‘James’) print(rstr)   This will replace the Bob with James and store it in […]

October 17th, 2020

‘in’ statement in String

  fruits=’banana’ bana in fruits Ans: True Python Function to confirm he vowel in the given input. def is_vowel(l): return […]

September 24th, 2020

awk Marking keywords

Marking keywords In the following example, we mark Java keywords in a source file. $wget nishantmunjal.com/dataset/mark_keywords.awk # the program adds […]

September 24th, 2020

awk Rock-paper-scissors

Rock-paper-scissors Rock-paper-scissors is a popular hand game in which each player simultaneously forms one of three shapes with an outstretched […]

September 24th, 2020

awk Spell Checking

Spell checking We create an AWK program for spell checking. $wget nishantmunjal.com/dataset/spellcheck.awk BEGIN { count = 0 i = 0 […]