From 5a66a2a7aa7daccf7886a8d1aa0f74e93feb9306 Mon Sep 17 00:00:00 2001 From: Vinesh nayak Date: Thu, 7 May 2026 12:17:03 +0530 Subject: [PATCH] fix: correct compound interest loop so interest compounds each year The formula was placed outside the for loop, meaning interest was only applied once regardless of years entered. Also fixed a typo 'investin' -> 'investing' and added round() for cleaner output. --- .../calculateCompoundInterest.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Calculate Compound Interest/calculateCompoundInterest.py b/Calculate Compound Interest/calculateCompoundInterest.py index a081393c..6c22d6da 100644 --- a/Calculate Compound Interest/calculateCompoundInterest.py +++ b/Calculate Compound Interest/calculateCompoundInterest.py @@ -4,7 +4,7 @@ print('How much money is currently in your account?') principal = float(input('Enter current amount in account: ')) -print ('How much money do you plan on investin monthly?') +print ('How much money do you plan on investing monthly?') monthly_invest = float(input('Enter amount: ')) print ('What do you estimate will be the yearly interest of this investment?') @@ -12,12 +12,9 @@ print(' ' ) monthly_invest = monthly_invest * 12 -final_amount = 0 +final_amount = principal for i in range(0, years): - if final_amount == 0: - final_amount = principal + final_amount = (final_amount + monthly_invest) * (1 + interest) -final_amount = (final_amount + monthly_invest) * (1 + interest) - -print("This is how much money you would have in your account after {} years: ".format (years) + str(final_amount)) +print("This is how much money you would have in your account after {} years: ".format(years) + str(round(final_amount, 2)))