Created
March 29, 2014 19:09
-
-
Save petrblahos/9861036 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_text_table(row_count, column_width): | |
""" | |
Makes a textual table with the numbered rows and 2 columns. The first | |
column is 5 characters wide, the 2nd and 3rd columns are column_width | |
characters wide. | |
Params: | |
row_count The number of rows. The rows are then numbered | |
1 to row_count | |
column_width The width of the second and third column. | |
""" | |
header_section = "" | |
body_section = "" | |
for i in range(column_width): | |
header_section += "-" | |
body_section += " " | |
separator = "+-----+" + header_section + "+" + header_section + "+" | |
print separator | |
column_fmt = "% " + str(column_width) + "s" | |
fmt = "|% 5d|" + body_section + "|" + body_section + "|" | |
for i in range(row_count): | |
print fmt % (i + 1, ) | |
print separator | |
make_text_table(3, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment