Python Tutorial

# Python Program to Calculate Simple Interest

## Calculate Simple Interest Python Program

This python program is used to compute simple interest for the user inputs principle, years and rate.

```# Compute simple interest for the user inputs p, n and r
#!/usr/bin/python

def calculate_simple_interest(p, n, r):
si = 0.0
si = float(p*n*r)/float(100);
return si;

if __name__ == '__main__':
p = float(input("Enter values\np: "));
n = int(input("n: "));
r = float(input("r: "));
simple_interest = calculate_simple_interest(p, n, r);
print("Simple interest value: %.2f" % simple_interest);
```
Output:
```\$ python simple_interest.py
Enter values
p: 100000
n: 3
r: 10.5
Simple interest value: 31500.00
```

## Print Simple Interest using format method

```# Compute simple interest for the user inputs p, n and r.
#!/usr/bin/python

def calculate_simple_interest(p, n, r):
si = 0.0
si = float(p*n*r)/float(100);
return si;

if __name__ == '__main__':
p = float(input("Enter values\np: "));
n = int(input("n: "));
r = float(input("r: "));
simple_interest = calculate_simple_interest(p, n, r);
print("Simple interest value: " + "{0:.2f}".format(simple_interest));
```
Output:
```\$ python simple_interest.py
Enter values
p: 100000
n: 3
r: 10.5
Simple interest value: 31500.00
```

Python Tutorial