I am having problems replicating the format as shown in:

what my results are:

I'm currently using:
print '{}.{:<20} {}.'.format(i,'sum so far:',sum)
I have tried left, right, and center alignment, but I just can't get the format that I want.
Convert the entire header portion, including the '.', to a string first, so you can calculate the width including it.
>>> '{:<20} sum so far: {}.'.format('{}.'.format(9), 123)
'9. sum so far: 123.'
>>> '{:<20} sum so far: {}.'.format('{}.'.format(10), 123)
'10. sum so far: 123.'
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