diff --git a/Calculate Compound Interest/calculateCompoundInterest.py b/Calculate Compound Interest/calculateCompoundInterest.py index a081393c..ea39eb1b 100644 --- a/Calculate Compound Interest/calculateCompoundInterest.py +++ b/Calculate Compound Interest/calculateCompoundInterest.py @@ -1,23 +1,36 @@ -print('How many years will you be saving?') -years = int(input('Enter years: ')) +def get_user_input(): + try: + years = int(input("šŸ”¢ How many years will you be saving? ")) + principal = float(input("šŸ’° Enter current amount in your account: ₹")) + monthly_invest = float(input("šŸ“„ Enter your monthly investment amount: ₹")) + interest = float(input("šŸ“ˆ Enter the expected yearly interest rate (e.g., 10% as 0.1): ")) + return years, principal, monthly_invest, interest + except ValueError: + print("āš ļø Please enter valid numeric values.") + return get_user_input() -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?') -monthly_invest = float(input('Enter amount: ')) +def calculate_future_value(years, principal, monthly_invest, annual_interest): + yearly_contribution = monthly_invest * 12 + amount = principal -print ('What do you estimate will be the yearly interest of this investment?') -interest = float(input ('Enter interest in decimal numbers (10% = 0.1): ')) -print(' ' ) + for _ in range(years): + amount = (amount + yearly_contribution) * (1 + annual_interest) -monthly_invest = monthly_invest * 12 -final_amount = 0 + return amount -for i in range(0, years): - if final_amount == 0: - final_amount = principal -final_amount = (final_amount + monthly_invest) * (1 + interest) +def main(): + print("šŸ’¼ Welcome to the Investment Growth Calculator šŸ’¼\n") -print("This is how much money you would have in your account after {} years: ".format (years) + str(final_amount)) + years, principal, monthly_invest, interest = get_user_input() + print("\nā³ Calculating investment growth...\n") + + future_value = calculate_future_value(years, principal, monthly_invest, interest) + + print("šŸ“Š After {} years, your total account balance will be: ₹{:.2f}".format(years, future_value)) + print("\nāœ… Thank you for using the Investment Calculator!") + + +if __name__ == "__main__": + main()