Skip to content

Commit 50d8d34

Browse files
author
Upkar Lidder
committed
adding compound interest
Signed-off-by: Upkar Lidder <[email protected]>
1 parent 40d7b4b commit 50d8d34

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

compound_interest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This script calculates yearly compound interest given principal, annual rate of interest and time period in years.
2+
# Do not use this in production. Sample purpose only.
3+
4+
# Author: Upkar Lidder (IBM)
5+
6+
# Input:
7+
# p, principal amount
8+
# t, time period in years
9+
# r, annual rate of interest
10+
11+
# Output:
12+
# compound interest = p * (1 + r/100)^t
13+
14+
15+
def compound_interest(p, t, r):
16+
return p * (pow((1 + r / 100), t))
17+
18+
19+
if __name__ == "__main__":
20+
p = float(input("Enter the principle amount: "))
21+
t = float(input("Enter the time period: "))
22+
r = float(input("Enter the rate of interest: "))
23+
24+
print("The compound interest is {:.2f}".format(compound_interest(p, t, r)))

0 commit comments

Comments
 (0)