How can I print this in tabulated form?
listex = range(nOfYears)
counter = 1
for i in listex:
if i ==0:
print counter, '\t',startingBalance,'\t', amountofinterest, '\t', next_balance
previous_balance = next_balance
total_interest +=amountofinterest
else:
counter += 1
amountofinterest = previous_balance*interestRate
total_balance = previous_balance+amountofinterest
print counter, '\t', previous_balance,'\t', amountofinterest, '\t', total_balance
previous_balance = total_balance
total_interest += amountofinterest
print '\n', "TOTAL BALANCE IS :", previous_balance
print "TOTAL AMOUNT OF INTEREST IS %.2f:" %(total_interest)
If you want to print this in the shape of a table in console, you should try the
tabulate
module which is really easy to use. (https://pypi.python.org/pypi/tabulate) Simple example:If you want to separate columns with
\t
character, you should check for the csv module and csv writer.