コンピュータサークルのこの問題に問題がありますが、これはおそらく非常に簡単なエクササイズですが、私は多くのことを学ぶべきだと思います。Pythonの行をスキップする方法
いずれかの入力に何も入力されていない場合に問題が発生します。最後の入力はなので、エラーを防ぐために他の入力をスキップする方法(goto
)を作成したかったのです。
私は、最適化/構造化の改善についてのご意見をお待ちしております。
ありがとうございます。
コード:このプログラムの
width = int(input())
second = input()
third = input()
fourth = input()
fifth = input()
sixth = input()
lenght_of_second = len(second)
lenght_of_third = len(third)
lenght_of_fourth = len(fourth)
lenght_of_fifth = len(fifth)
lenght_of_sixth = len(sixth)
periods = width - lenght_of_second
periods_on_side = periods // 2
reminder_periods = periods % 2
if second != "END":
print("." * reminder_periods + "." * periods_on_side + second + periods_on_side * ".")
periods = width - lenght_of_third
periods_on_side = periods // 2
reminder_periods = periods % 2
if third != "END":
print("." * reminder_periods + "." * periods_on_side + third + periods_on_side * ".")
periods = width - lenght_of_fourth
periods_on_side = periods // 2
reminder_periods = periods % 2
if fourth != "END":
print("." * reminder_periods + "." * periods_on_side + fourth + periods_on_side * ".")
periods = width - lenght_of_fifth
periods_on_side = periods // 2
reminder_periods = periods % 2
if fifth != "END":
print("." * reminder_periods + "." * periods_on_side + fifth + periods_on_side * ".")
periods = width - lenght_of_sixth
periods_on_side = periods // 2
reminder_periods = periods % 2
if sixth != "END":
print("." * reminder_periods + "." * periods_on_side + sixth + periods_on_side * ".")
、入力の最初の行は、整数幅です。次に、いくつかの行のテキストがあります。行は、テキストの終わりを示します。
テキストの各行について、テキストの各行の合計の長さが幅になるように、ピリオド..
を左右に追加して、中央のバージョンを印刷する必要があります。 (すべての入力行の幅は最大幅になります)
センタリングとは、可能な場合は、左側に追加され、右側に追加されるピリオドの数が同じであることを意味します。必要に応じて、右よりも左にもう1つの期間を許可します。例えば、入力用
:
13
Text
in
the
middle!
END
正しい出力は、私が10年後に来るかもしれないが、私はまだにあなたに単純な答えを提供します
.....Text....
......in.....
.....the.....
...middle!...
また、いくつかのコードを追加できますか? –
あなたの問題の[mcve]を教えてください... – Shadow
''例えば、入力用に "..あなたのテキストが途切れてしまった、入力例を完了してください – davedwards