Вот несколько способов создания таблицы умножения в Python:
Метод 1. Использование вложенных циклов
def multiplication_table(n):
for i in range(1, n+1):
for j in range(1, n+1):
print(i * j, end='\t')
print()
multiplication_table(10) # Change the parameter to set the desired size of the table
Метод 2. Использование списка
def multiplication_table(n):
table = [[i * j for j in range(1, n+1)] for i in range(1, n+1)]
for row in table:
print(*row, sep='\t')
multiplication_table(10) # Change the parameter to set the desired size of the table
Метод 3. Использование библиотеки NumPy
import numpy as np
def multiplication_table(n):
table = np.fromfunction(lambda i, j: (i+1)*(j+1), (n, n), dtype=int)
print(table)
multiplication_table(10) # Change the parameter to set the desired size of the table
Метод 4. Использование библиотеки pandas для создания DataFrame
import pandas as pd
def multiplication_table(n):
table = [[(i+1)*(j+1) for j in range(n)] for i in range(n)]
df = pd.DataFrame(table)
print(df)
multiplication_table(10) # Change the parameter to set the desired size of the table