Skip to content

Commit

Permalink
adding compound interest
Browse files Browse the repository at this point in the history
Signed-off-by: Upkar Lidder <[email protected]>
  • Loading branch information
Upkar Lidder committed Jan 12, 2022
1 parent 40d7b4b commit 50d8d34
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions compound_interest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This script calculates yearly compound interest given principal, annual rate of interest and time period in years.
# Do not use this in production. Sample purpose only.

# Author: Upkar Lidder (IBM)

# Input:
# p, principal amount
# t, time period in years
# r, annual rate of interest

# Output:
# compound interest = p * (1 + r/100)^t


def compound_interest(p, t, r):
return p * (pow((1 + r / 100), t))


if __name__ == "__main__":
p = float(input("Enter the principle amount: "))
t = float(input("Enter the time period: "))
r = float(input("Enter the rate of interest: "))

print("The compound interest is {:.2f}".format(compound_interest(p, t, r)))

0 comments on commit 50d8d34

Please sign in to comment.