The first balance is accidentally adding the interest before it can actually accumulate it. It should be the exact number the user inputs
The first balance is accidentally adding the interest before it can actually accumulate it. It should be the exact number the user inputs
# title
print("Investment Report")
print()
# get numbers from the user about the investment
starting_balance = float(input("Enter the investment amount: $"))
years = int(input("Enter the number of years: "))
rate = int(input("Enter the interest rate as a %: "))
interest = 0
total_interest = 0.0
# convert the rate to a decimal number
rate = rate / 100
# format the headings of our report
print("=" * 70)
print("{:5} {:>20} {:>20} {:>20}".format("Year", "Starting balance", "Interest amount", "Ending balance"))
print("=" * 70)
# initialize the accumulator for the interest
# compute and display results for each year
for each_year in range(1, years +1):
interest = round((starting_balance*rate),2)
total_interest += interest
starting_balance = round(starting_balance + interest,2)
print()
# calculate the interest starting balance*rate
# calculate the ending balance by adding the starting balance to interest
print("{:5} {:>20.2f} {:>20.2f} {:>20.2f}".format(each_year, starting_balance, interest, starting_balance+interest))
# replace the starting balance with the ending balance (using = sign)
# total_interest += interest amount (that I calculated earlier)
# Display the totals for the period
print("-" * 70)
print("Total balance ", "{:27.2f}".format(2850)) # you would replace the number with the ending balance variable
print("Total interest amount earned: ", "{:11.2f}".format(350)) # you would replace the number with the actual total interest calculated
print("-" * 70)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images