58.2k views
1 vote
(Financial application: compound value) Suppose you save $100 each month into savings account with an annual interest rate of 5%. Thus, the monthly interest rate is 0.05/12=0.00417. After the first month, the value in the account becomes 100 * (1 + 0.00417) = 100.417 After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252 After the third month, the value in the account becomes (100 + 201.252) * (1 + 0.00417) = 302.507 and so on. Write a program that prompts the user to enter a monthly saving amount, annual interest rate, and number of months and displays the account value after the user-defined number of months. Sample run:

User Kirchner
by
4.2k points

1 Answer

6 votes

Solution:

initial = float(eval(input('Enter the monthly saving amount: ')))

x = (1 + 0.00417)

month_one = initial * x

month_two = (initial + month_one) * x

month_three = (initial + month_two) * x

month_four = (initial + month_three) * x

month_five = (initial + month_four) * x

month_six = (initial + month_five) * x

print('The sixth month value is: '+str(month_six))

Don't forget the saving amount, and initialize the balance with that amount. Inside the loop, work out and add the interest and then add the saving amount for the next month.

balance = 801

for month in range(6):

balance = balance * (1.00417)

print(balance)

User MoustafaAAtta
by
4.9k points