Displaying Title


#1

How do I print the titles for the chart?
I thought of:
print("{0:10s} {1:10s} {2:10s} {3:10s} {4:10s}".format(“Taxable”, “Single”, “Married”, “Married”, “Head of”))
print("{0:10s} {1:10s} {2:10s} {3:10s} {4:10s}".format(“Income”, “”, “Joint”, “Separate”, “a House”))

Is there a more concise way to display for example “Taxable Income” in the same space 10s with “Income” under “Taxable” and the same for the other titles?

26 AM


#2

Without any additional library support, such as tablulate, what you have is adequate enough. Not sure what the 0, 1, 2, 3, 4 are doing though. The code works fine without them (in the interactive console, anyway)…

>>> print("{:10s} {:10s} {:10s} {:10s} {:10s}".format("Taxable", "Single", "Married", "Married", "Head of"));print("{:10s} {:10s} {:10s} {:10s} {:10s}".format("Income", "", "Joint", "Separate", "a House"))
Taxable    Single     Married    Married    Head of   
Income                Joint      Separate   a House   
>>> 

#3

Sorry, about that. The 0,1,2,3,4… supposed to be indexes of the things inside .format()


#4

Also, I noticed in your code:

print("{:10s} {:10s} {:10s} {:10s} {:10s}".format(“Taxable”, “Single”, “Married”, “Married”, “Head of”));print("{:10s} {:10s} {:10s} {:10s} {:10s}".format(“Income”, “”, “Joint”, “Separate”, “a House”))

That there’s a semi cool between the two prints --> print();print(). What is the semicolon doing?


#5

It is a statement separator so that both statements can be entered at once, thus not interfering with the output. In code, this wouldn’t be necessary but I was using the interactive console.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.