Investement report | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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)

21st Oct 2021, 5:01 PM
Rim Lamghari
Rim Lamghari - avatar
4 Answers
+ 1
your print statement is not formatted properly
21st Oct 2021, 5:31 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
What's wrong with it?
21st Oct 2021, 6:33 PM
Rim Lamghari
Rim Lamghari - avatar
0
Thank you so much
22nd Oct 2021, 7:36 PM
Rim Lamghari
Rim Lamghari - avatar
- 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)
22nd Oct 2021, 2:45 PM
Krishnam Raju M
Krishnam Raju M - avatar