问题是:For this program, the first line of input is an integer width. Then, there are some lines of text; the line "END" indicates the end of the text. For each line of text, you need to print out a centered version of it, by adding periods .. to the left and right, so that the total length of each line of text is width. (All input lines will have length at most width.) Centering means that the number of periods added to the left and added to the right should be equal if possible; if needed we allow one more period on the left than the right. For example, for input13
Text
in
the
middle!
END
正确的输出应该是
^{pr2}$
给出的提示是:For input line length of L, you should add (width-L)\\2 periods to the right side
以下是我目前为止的代码:width = int(input())
s1 = input()
periods_remain = width - len(s1)
L = periods_remain
periods_rtside = (width-L)//2
periods_leftside = width - periods_rtside
periods_rt_str = '.' * periods_rtside
periods_left_str = '.' * periods_leftside
line1 = periods_left_str + s1 + periods_rt_str
我的第1行结果看起来像“……….Text..”而不是…..Text。。。。在
我的问题似乎是L。我不知道如何定义L。谢谢!在