I want to produce the following output:
20 $ 476321.30 $ 923268.18 $ 1859015.31 $ 3840898.15
with this code:
for age in range(20, 70, 5):
for percentage in range(4, 12, 2):
result = calc_final_balance(age, amount_saved, percentage)
print(age, "\t $" + format(result, '.2f').rjust(10), end="")
print()
but the problem is, the age is always printed after the amount:
20 $ 476321.3020 $ 923268.1820 $ 1859015.3120 $ 3840898.15
You can easily do this. Just print it in your first, "higher" loop:
for age in range(20, 70, 5):
print(age, end=" ") #end is space
for percentage in range(4, 12, 2):
result = calc_final_balance(age, amount_saved, percentage)
print("\t $" + format(result, '.2f').rjust(10), end=" ")
print()
This way it will produce something like:
20 $ 476321.30 $ 923268.18 $ 1859015.31 $ 3840898.15
70 $ someamount $ someamount $ someamount $ someamount
5 $ someamount $ someamount $ someamount $ someamount
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With