Ask AI on The Internet
Question: Write a Python program to calculate the compound interest on a deposit using the formula A = P(1+r/n)nt, where A is the final amount, P is the principal, r is the annual interest rate, n is the number of times interest is compounded per year, and t is the time in years. Given the following formula used for calculating the final amount, A= where A is the final amount, P is the principal, r is the annual interest rate, n is the number of times interest is compounded per year, and t is the time in years.
Here's a Python program to calculate the compound interest on a deposit using the provided formula: ```python def compound_interest(principal, rate, compounding_frequency, years): final_amount = principal * (1 + rate / compounding_frequency) ** (compounding_frequency * years) return final_amount # Input values principal = float(input("Enter the principal amount: ")) rate = float(input("Enter the annual interest rate (decimal): ")) compounding_frequency = int(input("Enter the number of times interest is compounded per year: ")) years = int(input("Enter the time in years: ")) # Calculate compound interest and display results final_amount = compound_interest(principal, rate, compounding_frequency, years) interest_earned = final_amount - principal print(f"The final amount after {years} years is: {final_amount:.2f}") print(f"The interest earned is: {interest_earned:.2f}") ``` To use this program, copy and paste the code into a Python interpreter or IDE, then run it. You'll be prompted to enter the principal amount, annual interest rate (as a decimal), the number of times interest is compounded per year, and the time in years. The program will then calculate the final amount and the interest earned and display the results.
A new large language model has been made available since this question was asked.
To generate an updated answer from the new model, click the button below.
Think your answer is better than the AI's? Post it below.
Other Most Relevant Posts:
Question Tags
If you want your question answered by an AI, click here.
Post your own comment: