From 66d905f7c90e9cdf32f3e6134ee3b387692275bb Mon Sep 17 00:00:00 2001 From: shariik Date: Tue, 16 Dec 2025 11:11:01 +0500 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=2018?= =?UTF-8?q?=20=D0=BF=D0=B0=D1=80=D0=B0=D0=B3=D1=80=D0=B0=D1=84=202.3=20?= =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.3_lesson.18.20.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 2.3_lesson.18.20.py diff --git a/2.3_lesson.18.20.py b/2.3_lesson.18.20.py new file mode 100644 index 0000000..4035e42 --- /dev/null +++ b/2.3_lesson.18.20.py @@ -0,0 +1,41 @@ +****Задание 18 Параграф 2.3*** +**** Праздники приближаются, и коллеги великого математика снова хотят его порадовать. +На этот раз — с помощью ещё более красивых математических ёлок! + +Вас снова зовут в качестве главного креативного программиста. +Нужно сделать так, чтобы каждая строка ёлки была аккуратно выровнена по центру — строго, симметрично, празднично.**** + +if name == "main": + limit = int(input()) + + counter = 0 + width = 1 + max_length = 0 + + while counter <= limit: + string_length = 0 + for position in range(width): + counter += 1 + if counter <= limit: + string_length += len(str(counter)) + if position < width - 1 and counter < limit: + string_length += 1 + + if max_length < string_length: + max_length = string_length + + width += 1 + + counter = 0 + width = 1 + + while counter <= limit: + string = '' + for position in range(width): + counter += 1 + if counter <= limit: + string += str(counter) + if position < width - 1 and counter < limit: + string += ' ' + width += 1 + print(f'{string:^{max_length}}')