# Here ,We are going to write python program to compute simple interest and compound interest.

The Simple **Interest and compound interest formulas** are given as,

S.I. = Principal × Rate × Time |

C.I. = Principal (1 + Rate)^{Time} − Principal |

## Example Problems Using Interest Formulas

Example : Principle amount is 4000 ,rate is 7 % and time is 2 years then calculate simple and compound interest

Solution:

Simple Interest = Principle × Rate × Time = PTR/100

⇒ Simple Interest = 4000 × (7 ⁄ 100) × 2

⇒ Simple Interest = 560

∴ The simple Interest for 2 years is Rs. 560

Compound Interest = Principal × (1 + Rate)^{Time} − Principal

So, Compound Interest = 4000 × (1 + 7 ⁄ 100)^{2} − 4000

⇒ Compound Interest = (4000 × 1.1449) − 4000

⇒ Compound Interest = 580

∴ The compound interest for 2 years is Rs. 580

## Program

```
# Ask user to enter principle amount
p=float(input("Enter the principle amount:"))
# Enter time in years
t=int(input("Enter the time(years):"))
# Input rate
r=float(input("Enter the rate:"))
# Calculating simple interest
si=(p*r*t)/100
# Displaying simple interest
print("The simple interest is:",si)
# Calculating compound interest
ci = p * ((1 + (r / 100 ))** t) - p
# Displaying compound interest
print("Compound interest is %.2f" % ci)
```

## Output:

>> %Run 'simpleandcompund interest.py' Enter the principle amount:4000 Enter the time(years):2 Enter the rate:7 The simple interest is: 560.0 Compound interest is 579.60

In the above code, we have taken inputs from users for values of principle amount,time in years and rate in percentage. And the calculate simple interest by multiplying all 3 values which we have taken from user and dividing all by 100 and compound interest is also calculated by using stated formulas (see in program)

## Other python programs:

- To find the sale price of an item with given cost and discount
- To calculate perimeter/ circumference and area of shapes such as triangle, rectangle, square and circle