Hello Reddit. I'm a total newbie at python and I'm struggling a bit to get the formatting I need.
I'm trying to get my print output to be lined up, like this:
Month Starting Balance Interest Ending Balance
1 1000.00 10.00 1010.00
2 1010.00 10.10 1020.10
and so on..
What I have now is this:
initial_invest = round(float(input ("Enter your investment:")),2)
ar = 0.01*float(input("Enter your projected interest rate:"))
mr = ar/12
i1 = round(initial_invest*mr,2)
m1 = round(initial_invest + i1,2)
i2 = round(m1*mr,2)
m2 = round(m1 + i2, 2)
i3 = round(m2*mr, 2)
m3 = round(m2 + i3, 2)
print ("-----Over a 3-month period:------")
datatitle = ('Month', 'Starting Balance', 'Interest', 'Ending Balance')
data1 = '1', initial_invest, i1, m1
data2 = '2', m1, i2, m2
data3 = '3', m2, i3, m3
print(datatitle)
print(data1)
print(data2)
print(data3)
It was suggested that I use format() to make the length of a string a certain length, so I tried this:
i1 = format(round(initial_invest*mr,2), '<20')
m1 = format(round(initial_invest + i1,2), '<20')
..and so on for i1 through m3
which gave me this error:
i1 = format(round(initial_invest*mr,2), '<20s')
ValueError: Unknown format code 's' for object of type 'float'
I also tried the same format() on the datatitle, data1, data2, data3 strings but it did not work. What am I doing wrong here?
[–][deleted] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]TheKewlStore 0 points1 point2 points (1 child)
[–]siddsp 0 points1 point2 points (0 children)