Skip to content

Python 103 字串格式化輸出

Python String TQC

題目說明:

請撰寫一程式,輸入四個單字,然後將這四個單字以欄寬為10、欄與欄間隔一個空白字元、每列印兩個的方式,先列印向右靠齊,再列印向左靠齊,左右皆以直線 |(Vertical bar)作為邊界。

範例輸入
I
enjoy
learning
Python

範例輸出

|         I      enjoy|
|  learning     Python|
|I          enjoy     |
|learning   Python    |

Solution

1
2
3
4
5
6
7
8
a = input()
b = input()
c = input()
d = input()
print("|{:>10s} {:>10s}|".format(a, b))
print("|{:>10s} {:>10s}|".format(c, d))
print("|{:<10s} {:<10s}|".format(a, b))
print("|{:<10s} {:<10s}|".format(c, d))

Last update : 13 novembre 2024
Created : 13 novembre 2024

Comments

Comments