Created
March 29, 2014 19:02
-
-
Save petrblahos/9860933 to your computer and use it in GitHub Desktop.
This file contains 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): | |
print "+", | |
for width in range(5): | |
print "-", | |
for width in range(2): | |
print "+", | |
for width in range(column_width): | |
print "-", | |
print "+" | |
''' | |
Tak, lepší je si to prvně připravit, a pak to teprve vytisknout najednou. | |
To vyřeší problém s mezerama. | |
row = "+-----+ | |
protože tam máme vždycky těch 5. Pak samozřejmně: | |
segment = "" | |
for i in range(column_width): | |
segment += " " | |
row += segment + "+" + segment + "+" | |
print segment | |
''' | |
for rows in range(row_count): | |
print "|", | |
row = str(rows+1) | |
print '%5s' % row, | |
''' | |
Tady je lepší formátovat přímo jako číslo, tedy %d. Dáš % 5d (mezera za %). | |
row = "|% 5d|%s|%s|" % (row + 1, column, column) | |
kde column bude patřičný počet mezer: | |
column = "" | |
for i in range(column_width): | |
column += " " | |
''' | |
for width in range(2): | |
print "|", | |
for width in range(column_width): | |
print " ", | |
print "|" | |
for width in range(5): | |
print "-", | |
for width in range(2): | |
print "+", | |
for width in range(column_width): | |
print "-", | |
print "+" | |
make_text_table(12, 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment