Код:
def corrector(string, width, symbol):
spaces_to_add = width - len(string)
if spaces_to_add % 2 != 0:
left_spaces = spaces_to_add // 2
right_spaces = spaces_to_add // 2 + 1
else:
right_spaces = spaces_to_add // 2
formatted_string = f'{symbol * left_spaces}{string}{symbol * right_spaces}'
return formatted_string
input_string = "Hello"
width = 15
fill_symbol = "-"
result = corrector(input_string, width, fill_symbol)
print(result)
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Код:
def corrector(string, width, symbol):
spaces_to_add = width - len(string)
if spaces_to_add % 2 != 0:
left_spaces = spaces_to_add // 2
right_spaces = spaces_to_add // 2 + 1
else:
left_spaces = spaces_to_add // 2
right_spaces = spaces_to_add // 2
formatted_string = f'{symbol * left_spaces}{string}{symbol * right_spaces}'
return formatted_string
input_string = "Hello"
width = 15
fill_symbol = "-"
result = corrector(input_string, width, fill_symbol)
print(result)