Задание 18 параграф 2.3 сделал
This commit is contained in:
parent
640885ac3b
commit
66d905f7c9
41
2.3_lesson.18.20.py
Normal file
41
2.3_lesson.18.20.py
Normal 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}}')
|
||||
Loading…
Reference in a new issue