TQC+ 程式語言 Python 3 _103 字串格式化輸出

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

I
enjoy
learning
Python
範例輸出:
|         I      enjoy|
|  learning     Python|
|I          enjoy     |
|learning   Python    |
程式碼:
a = input()
b = input()
c = input()
d = input()

print ('|{:>10} {:>10}|'.format(a,b))
print ('|{:>10} {:>10}|'.format(c,d))
print ('|{:<10} {:<10}|'.format(a,b))
print ('|{:<10} {:<10}|'.format(c,d))

沒有留言:

張貼留言