Learn about Program to Calculate Compound Interest in Python in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Program to Calculate Compound Interest in Python
# Python program to find compound interest
# inputs from user
principal = float(input('principal amount: '))
rate = float(input('interest rate: '))
time = float(input('time (in years): '))
number = float(input('Number of times that interest is compounded per year: '))
# conversion rate
rate = rate/100
# calculating the total amount
amount = principal * pow( 1+(rate/number), number*time)
# calculating the compound interest
ci = amount - principal
# print result
print('Compound interest = %.2f' %ci)
print('Total amount = %.2f' %amount)
Output:
principal amount: 5000 interest rate: 3 time (in years): 5 Number of times that interest is compounded per year: 3 Compound interest = 804.84 Total amount = 5804.84
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Python Program to Find Simple Interest using Function