python根據文本大小打印合適的方框


print()
txt = input("請輸入你要顯示的文本:")

screen_width=100
txt_width = len(txt) + 6
box_width = 3
left_margin = (screen_width - txt_width ) //2

print()
print(' ' * left_margin + '+' + '-' * (txt_width) + '+')
print(' ' * left_margin +'|' + ' ' * (txt_width) + '|')
print(' ' * left_margin +'|' + ' ' * (box_width) + txt + ' ' * (box_width) + '|')
print(' ' * left_margin +'|' + ' ' * (txt_width) + '|')
print(' ' * left_margin +'+' + '-' * (txt_width) + '+')
print()

input("輸入Enter鍵結束此程序")

image

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章