project_python/2.3_lesson.14.20.py

27 lines
1.3 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.

****Задание 14 Параграф 2.3***
**** Обычные прямоугольники — это, конечно, хорошо… но дети быстро теряют к ним интерес.
Поэтому воспитательница просит вас придумать что-нибудь поинтереснее. Например — числовую змейку!
В этой змейке строки чередуются: одна идёт слева направо, следующая — справа налево, потом снова слева направо… и так далее.
Настоящее приключение для тех, кто учит числа!
Напишите программу, которая строит числовую змейку из чисел от 1 до N × M.****
if name == "main":
# Наивный метод
height = int(input())
width = int(input())
ceil_width = len(str(width * height))
if height > 0 and width > 0:
for row in range(height):
for column in range(width):
if (row % 2) == 0:
num = row * width + column + 1
else:
num = (row + 1) * width - column
print(f'{num:>{ceil_width}}', end=' ')
print()