Skip to content

Instantly share code, notes, and snippets.

@kebot
Last active August 29, 2015 13:57
Show Gist options
  • Save kebot/9886345 to your computer and use it in GitHub Desktop.
Save kebot/9886345 to your computer and use it in GitHub Desktop.
# first we build a 20 * 20 table
# each table contains a char value that can be '*' or '-'
table = [['-' for i in range(0, 20)] for i in range(0, 20)]
def print_table(table):
""" then we define a function that can print the table into screen"""
for row in table:
print " ".join(row)
# let's try to print the table
print_table(table)
# the output should looks like this
"""
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
"""
# most important step
def process_table(table):
for x in range(0, len(table)):
x_num = x + 1
row = table[x]
for y in range(0, len(row)):
y_num = y + 1
result = x_num * y_num
if result <= 20:
# print x_num, '*', y_num , '=', result
table[result-1][x] = '*'
table[result-1][y] = '*'
process_table(table)
print_table(table)
# the_result_should_be like this
"""
* - - - - - - - - - - - - - - - - - - -
* * - - - - - - - - - - - - - - - - - -
* - * - - - - - - - - - - - - - - - - -
* * - * - - - - - - - - - - - - - - - -
* - - - * - - - - - - - - - - - - - - -
* * * - - * - - - - - - - - - - - - - -
* - - - - - * - - - - - - - - - - - - -
* * - * - - - * - - - - - - - - - - - -
* - * - - - - - * - - - - - - - - - - -
* * - - * - - - - * - - - - - - - - - -
* - - - - - - - - - * - - - - - - - - -
* * * * - * - - - - - * - - - - - - - -
* - - - - - - - - - - - * - - - - - - -
* * - - - - * - - - - - - * - - - - - -
* - * - * - - - - - - - - - * - - - - -
* * - * - - - * - - - - - - - * - - - -
* - - - - - - - - - - - - - - - * - - -
* * * - - * - - * - - - - - - - - * - -
* - - - - - - - - - - - - - - - - - * -
* * - * * - - - - * - - - - - - - - - *"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment