I am very very new to Python, so don't laugh at my code. Plus, I looked at this site for "code tags" but could not find out how to properly post -- so I am just going to copy and paste. Part 2 of my code is where I talk about the column of numbers not right justifying. Part 3 generates an error as you will see when it is run -- I was going to work on that after I fixed Part 2. thanks for helping (how do I use the code tags so when I copy and paste it comes out correct?)
# Part 1
your_start_age = 62
her_start_age = 61
start_year = 2017
taxableequity = 100000
taxablefixedincome = 200000
taxablecash = 50000
taxableequitygwth = 5
taxablefixedincomediv = 6
taxablecashdiv = 4
# Part 2
f = open("test.txt", "w")
print("Year", "\t", "Your", "\t", "Her", "\t", "Taxable", "\t", "Taxable", "\t", "Taxable")
print("\t", "\t", "Age", "\t", "Age", "\t", "Equity", "\t", "Fixed Inc", "\t", "Cash")
for y in range(81):
print(start_year, "\t", your_start_age, "\t", her_start_age, "\t", '{:>5}${:,.0f}'.format('',taxableequity), "\t", '${:>5,.0f}'.format(taxablefixedincome), "\t", '${:>5,.0f}'.format(taxablecash))
f.write('{} {} {} {} {} {} {} {} {}\n'.format(start_year, your_start_age, her_start_age, taxableequity, taxablefixedincome, taxablecash, taxableequitygwth, taxablefixedincomediv, taxablecashdiv))
your_start_age += 1
her_start_age += 1
start_year += 1
taxableequity = taxableequity * (1+ (taxableequitygwth/100))
taxablefixedincome = taxablefixedincome * (1 + (taxablefixedincomediv/100))
taxablecash = taxablecash * (1 + (taxablecashdiv/100))
f.close()
# Part 3
print("Year", "\t", "Your", "\t", "Her", "\t", "Taxable", "\t", "Taxable", "\t", "Taxable")
print("\t", "\t", "Age", "\t", "Age", "\t", "Equity", "\t", "Fixed Income", "\t", "Cash")
with open("test.txt", "r") as opened_file:
for line in opened_file:
start_year, your_start_age, her_start_age, taxableequity, taxablefixedincome, taxablecash, taxableequitygwth, taxablefixedincomediv, taxablecashdiv = line.split()
print(start_year, "\t", your_start_age, "\t", her_start_age, "\t", '${:,.0}'.format(taxableequity), "\t",'${:,.0}'.format(taxablefixedincome), "\t", '${:,.0}'.format(taxablecash))