project_python/2.3_lesson.18.20.py
2025-12-15 14:04:11 +05:00

41 lines
1.5 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.

****Задание 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}}')