Last active
August 29, 2015 13:57
-
-
Save kebot/9886345 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
# 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