Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions compound_interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Do not use this in production. Sample purpose only.

# Author: Upkar Lidder (IBM)
# Updated by HamzaIDM

# Input:
# p, principal amount
Expand All @@ -10,15 +11,26 @@

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

import sys

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

def main():

if __name__ == "__main__":
p = float(input("Enter the principal amount: "))
t = float(input("Enter the time period: "))
r = float(input("Enter the rate of interest: "))
# for speed
read = sys.stdin.readline
write = sys.stdout.write

write("Enter the principal amount: ")
p = float(read())
write("Enter the time period: ")
t = float(read())
write("Enter the interest rate: ")
r = float(read())

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


if __name__ == "__main__":
main()