Вы можете печатать с print_function
, используя sep='\n'
. Вы можете удалить [
, ]
с некоторым форматированием, но основная идея здесь. Я также исправляю небольшую ошибку, посмотрите на комментарий:
from __future__ import print_function
table = []
row_one = int(input("Enter row number:"))
column = int(input("Enter column number:"))
for j in range(1, row_one + 1):
temp = [] # temp need to be outside of the loop to work as intended
for i in range(1, column + 1):
temp.append(j * i)
table.append(temp) # note the identation of this
print(*table, sep='\n')
Выход:
Enter row number:4
Enter column number:4
[1, 2, 3, 4]
[2, 4, 6, 8]
[3, 6, 9, 12]
[4, 8, 12, 16]
Бонус: необходимые однострочники Python
table = [[(j+1) * (i+1) for i in range(column)] for j in range(row_one)]
print(*(' '.join(map(str,line)) for line in table), sep='\n')