project_python/2.3_lesson.15.20.py

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

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