project_python.2.4/lesson.16.py

44 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

''' ****** Задание 16 из 20 Параграф 2.4 *********
* Пора навести порядок и добавить стиля!
Ваш новый заказчик просит:
одинаковую ширину столбцов,
выравнивание по центру,
и — внимание! — рамки между ячейками.
Формат ввода
В первой строке записан требуемый размер таблицы. Во второй строке — ширина столбцов.
Формат вывода
Таблица умножения заданного размера и вида.
Пример 1
Ввод
3
3
Вывод
1 | 2 | 3
-----------
2 | 4 | 6
-----------
3 | 6 | 9
'''
if __name__ == "__main__":
size = int(input())
width = int(input())
for row in range(1, size + 1):
for col in range(1, size + 1):
number = row * col
print(f'{number:^{width}}', end='')
if col < size:
print('|', end='')
print()
if row < size:
print('-' * (width * size + size - 1))