The first balance is accidentally adding the interest before it can actually accumulate it. It should be the exact number the user inputs

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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)

**Interest Calculation Example**

### Enter the interest rate as a %: 5

| Year | Starting Balance | Interest Amount | Ending Balance |
|------|------------------|-----------------|----------------|
| 1    | 2625.00          | 125.00          | 2750.00        |
| 2    | 2756.25          | 131.25          | 2887.50        |
| 3    | 2894.06          | 137.81          | 3031.87        |

---

### Total Balance: 2850.00
### Total Interest Amount Earned: 350.00

---

**Process finished with exit code 0**

This tabular representation shows the computation of interest over three years with a 5% interest rate. Starting and ending balances for each year are presented, along with the interest earned. The bottom section summarizes the total balance and total interest amount accumulated over the period.
Transcribed Image Text:**Interest Calculation Example** ### Enter the interest rate as a %: 5 | Year | Starting Balance | Interest Amount | Ending Balance | |------|------------------|-----------------|----------------| | 1 | 2625.00 | 125.00 | 2750.00 | | 2 | 2756.25 | 131.25 | 2887.50 | | 3 | 2894.06 | 137.81 | 3031.87 | --- ### Total Balance: 2850.00 ### Total Interest Amount Earned: 350.00 --- **Process finished with exit code 0** This tabular representation shows the computation of interest over three years with a 5% interest rate. Starting and ending balances for each year are presented, along with the interest earned. The bottom section summarizes the total balance and total interest amount accumulated over the period.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education