project_python/2.3_lesson.13.20.py

23 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.

****Задание 13 Параграф 2.3***
**** Давайте ещё немного поможем воспитательнице — на этот раз с новым вариантом числового прямоугольника.
На первый взгляд он похож на предыдущий…
Но здесь числа идут по столбцам, а не по строкам. И это меняет всё!
Напишите программу, которая заполняет прямоугольник числами от 1 до N × M, по столбцам, а не по строкам и форматирует их так, чтобы все столбцы были одинаковой ширины.****
if name == "main":
# Наивный метод
height = int(input())
width = int(input())
cell_width = len(str(height * width))
for i in range(1, height + 1):
for j in range(i, i + height * (width - 1) + 1, height):
print(f'{j:>{cell_width}}', end=' ')
if j == i + height * (width - 1):
print()