Skip to content

Instantly share code, notes, and snippets.

@petrblahos
Created March 29, 2014 19:18
Show Gist options
  • Select an option

  • Save petrblahos/9861165 to your computer and use it in GitHub Desktop.

Select an option

Save petrblahos/9861165 to your computer and use it in GitHub Desktop.
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 = "+-----+" + "-" * column_width + "+" + "-" * column_width + "+"
column_section = " " * column_width + "|"
column_section = column_section * 2
print header
for i in range(row_count):
print ("|% 5d|" + column_section) % (i + 1, )
print header
make_text_table(3, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment