Сделал 18 параграф 2.3

This commit is contained in:
shariik 2025-12-15 14:04:11 +05:00
parent a24ba31329
commit 049353e6cc

41
2.3_lesson.18.20.py Normal file
View file

@ -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}}')