我要this intro to python course online
问题显示为:
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 input
13
Text
in
the
middle!
END
正确的输出将是
.....Text....
......in.....
.....the.....
...middle!...
给出的提示是:
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
我的line1结果看起来像是“ ……… Text ..”而不是… Text ….
我的问题似乎是L.我不确定如何定义L.谢谢!