[Tutor] Field Width
Dave Angel
davea at davea.name
Thu Sep 19 11:24:37 CEST 2013
On 18/9/2013 12:50, Jenny Allar wrote:
> I'm only a few days in to learning Python, so please bear with me.
>
> I need to line up the decimals on the printed information but I cannot get
> the text to look uniform at all.
>
>
> Here is my code:
>
<snip>
>
> # Print infomation
> print("The cost of the carpet is $", format(subtotal,'9,.2f'))
> print("The flat fee is $", format(fee,'9,.2f'))
> print("The tax is $", format(tax_rate,'9,.2f'))
> print("The total due is $", format(total_due,'9,.2f'))
>
Have you tried lining it up in the source?
# Print infomation
print("The cost of the carpet is $", format(subtotal,'9,.2f'))
print("The flat fee is $", format(fee,'9,.2f'))
print("The tax is $", format(tax_rate,'9,.2f'))
print("The total due is $", format(total_due,'9,.2f'))
The format() method can handle variability in the floating point number,
but it does nothing to guess what else you put on the line.
Does that help?
--
DaveA
More information about the Tutor
mailing list