代码示例:
#获取句子长度
sentence = input('Plese input a sentence:')#He's very naughty boy
screen_width =100
#获取文本的长度
text_width =len(sentence)
#文本的宽度
box_width = text_width +10
#计算出左右两边需空余的格式数[左边缘,右边缘]
left_margin = (screen_width - box_width)//2
box_left_margin = (box_width-text_width)//2 #打印屏幕宽度
print('='*100)
print(' '*left_margin + '+' + '-' *(box_width-2) + '+')
print(' '*left_margin + '|' + ' ' *(box_width-2) + '|')
print(' '*left_margin + '|' + ' '*(box_left_margin-1) + sentence + ' '*(box_left_margin-1) + '|')
print(' '*left_margin + '|' + ' ' *(box_width-2) + '|')
print(' '*left_margin + '+' + '-' *(box_width-2) + '+')
#打印屏幕宽度
print('='*100)
运行结果:

Plese input a sentence:I love you Fiona
====================================================================================================
                        +------------------------+
                        |            |
                        |   I love you Fiona    |
                        |            |
                        +------------------------+
====================================================================================================

最新文章

  1. golang print struct with key
  2. Maven私服Nexus3.x环境构建操作记录
  3. yii2权限控制rbac之rule详细讲解(转)
  4. LTE工作过程
  5. 蓝牙的OBEX协议
  6. crontab 定时任务格式
  7. window.print打印指定div实例代码
  8. 5A的肖特基二极管 SK5x / SK5xx
  9. linux命令ps aux|grep xxx详解
  10. 简易的highcharts公共绘图模块封装--基于.net mvc
  11. windows 配置host
  12. iOS 将UIColor转换为UIImage
  13. FZU 2256 迷宫
  14. NopCommerce开源项目中很基础但是很实用的C# Helper方法
  15. MVC 使用缓存
  16. Codeforces Round #436 (Div. 2)D. Make a Permutation! 模拟
  17. forEach 如何提前终止 跳出运行
  18. HTML&javaSkcript&CSS&jQuery&ajax(三)
  19. NLP 工具类库
  20. bigtable原理

热门文章

  1. java.sql.SQLException: Could not commit with auto-commit set on
  2. 关于Mac系统中my sql 和navicat for mysql 的连接问题。
  3. Linux基本系统优化
  4. Codeforces 1167E(思路、数据处理)
  5. ASP .NET Core 2.1 HTTP Error 502.5 – Process Failure
  6. Ubuntu14.04 使用scp远程传输命令进行服务器文件互传
  7. AngularJS(一):概述
  8. mysql操作封装
  9. 利用bintray-release插件上传到Bintray- HTTP/1.1 404 Not Found [message:Repo 'maven' was not found]问题解决
  10. 【js类库Raphaël】使用raphael.js根据点坐标绘制平滑曲线