0
Investement report
Hi. Please can someone tell me what is wrog with my code?(The formating part line 4) amount = int(input("Enter the investement amount:")) years = int(input("Enter the number of years:")) rate = int(input("Enter the rate as a %:")) print("%4s"%"Year" , "%5s"%"Starting balance" , "%6s%"%"Interest" , "%7s"%"Ending balance") for i in range(years): interest = (amount*rate)/100 endingbalance = amount + interest print(i , "%5d"%amount , "%6d"%interest , "%7d"%endingbalance) print("Ending balance is" , endingbalance)
4 Réponses
+ 1
your print statement is not formatted properly
0
What's wrong with it?
0
Thank you so much
- 1
The problem is the 4th line. I changed the code little bit, check it
amount = int(input("Enter the investement amount:"))
years = int(input("Enter the number of years:"))
rate = int(input("Enter the rate as a %:"))
endingbalance = 0
print("%4s" % "Year", "%8s" % "Starting balance", "%6s" % "% Interest", "%7s" % "Ending balance")
for i in range(years):
interest = (amount*rate)/100
endingbalance = amount + interest
print(i, "%15d" % amount, "%10d" % interest, "%12d" % endingbalance)
amount = endingbalance
print("Ending Balance is", endingbalance)