- Home
- Assessment

48 / 79

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):
# This is where you code go.
# compute comp_interest
return comp_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.

Please use the iterative approach as mentioned above instead of direct formulae to calculate the compounded interest.

XP

Taking you to the next exercise in seconds...

Checking Please wait.

Success

Error