#/usr/bin/python
# -*- coding:utf-8 -*-

# width 单个网格有多少个 - 宽度
# height 单个网格有多少个 | 高度
# lateral 横向有多少个网格
# vertical 竖向有多少个网格
def printGrid(width,height,lateral,vertical):
for i in range(vertical):
print_lateral(lateral,width)
for n in range(height):
print_vertical(lateral,width)
print print_lateral(lateral,width) def print_vertical(lateral,width):
for i in range(lateral):
print '|',
print ' '*width, # print '  '* (width-1), print ' ',
print '|' def print_lateral(lateral,width):
for i in range(lateral):
print '+',
print '-' * width, # print '- ' * (width-1), print '-',
print '+' if __name__ == '__main__':
printGrid(5,5,3,2)
+ ----- + ----- + ----- +     # + - - - -  - + - - - -  - + - - - -  - +
| | | |     
| | | |
| | | |
| | | |
| | | |
+ ----- + ----- + ----- +
| | | |
| | | |
| | | |
| | | |
| | | |
+ ----- + ----- + ----- +

来自 http://www.codingpy.com/books/thinkpython2/03-functions.html 的题目

教程下方给出的答案 :http://greenteapress.com/thinkpython2/code/grid.py  感觉好麻烦

python 打印 网格的更多相关文章

  1. Python打印格式化与字符串

    关于Python打印格式化与字符串,比较全面的总结,希望对大家有帮助~ # -*- coding: cp936 -*- ''' 打印格式 ''' print "a" print & ...

  2. python打印表格式数据,留出正确的空格和段落星号或注释

    python打印表格式数据,留出正确的空格,格式化打出 代码如下: def printPicnic(itemsDict,leftWidth,rightWidth): print('PICNIC ITE ...

  3. python 打印 emoji

    python 打印 emoji 如需转发,请注明出处:小婷儿的python  https://www.cnblogs.com/xxtalhr/p/10486506.html 一.Unicode字符集: ...

  4. python打印列表的下标和值的例子:

    python打印列表的下标和值的例子: In [1]: list01=[1,4,5] In [10]: def funct01(ll):   ....:     for index,value in ...

  5. 【Python】Python 打印和输出更多用法。

    Python 打印和输出 简述 在编程实践中,print 的使用频率非常高,特别是程序运行到某个时刻,要检测产生的结果时,必须用 print 来打印输出. 关于 print 函数,前面很多地方已经提及 ...

  6. python 打印 九九表

    用Python 打印九九表. print 每打印一行默认会带有换行, 在print语句后加上,end = 't' 会变成tab. 排版会好点. def main(): for i in range(1 ...

  7. python打印表格式数据-星号或注释

    python打印表格式数据,留出正确的空格,格式化打出 代码如下: def printPicnic(itemsDict,leftWidth,rightWidth): print('PICNIC ITE ...

  8. python 打印 str 字符串的实际内容 repr(str)

    python 打印 str 字符串的实际内容 repr(str) s = 'aa' print(repr(s))

  9. python打印日志log

    整理一个python打印日志的配置文件,是我喜欢的格式. # coding:utf-8 # 2019/11/7 09:19 # huihui # ref: import logging LOG_FOR ...

随机推荐

  1. http协议 幂等性的理解

    HTTP GET.DELETE.PUT.POST四种主要方法的幂等性的理解 GET: GET请求是幂等的,多次的GET请求,不应该修改数据状态,只是查询. DELETE Delete请求也具有幂等性, ...

  2. djangocms安装技巧

    首先python的版本要高一些,否则安装django-cms会报错 安装cmsinstaller不能够正常下载 利用virtualenv进行安装配置 注意中文的配置 djangocms配置中文 dja ...

  3. Node聊天程序实例04:chat_ui.js

    作者:vousiu 出处:http://www.cnblogs.com/vousiu 本实例参考自Mike Cantelon等人的<Node.js in Action>一书. 这个程序在客 ...

  4. zookeeper 故障重连机制

    一.连接多个服务器,用逗号隔开 如果在连接时候zk服务器宕机 To create a client session the application code must provide a connec ...

  5. WinForm中MouseEnter和MouseLeave混乱的问题

    MouseEnter+MouseLeave不行,我用了MouseMove+MouseLeave,效果一样 最近做个聊天的系统,仿照qq的界面设计,像qq聊天界面中字体.表情.截图等图片,鼠标放上去显示 ...

  6. spa 单页面解决浏览器back front 问题

    1.angular router reloadOnSearch:true(default) | false  默认为true,当url的hash发生改变,页面新渲染,component会重新加载(初始 ...

  7. spring-boot 之 使用Admin监控应用

    https://yq.aliyun.com/articles/2322 ************************************* 摘要: Spring Boot提供的监控接口,例如: ...

  8. PPTP协议

    PPTP协议 PPTP(Point-to-Point Tunneling Protocol)点对点隧道协议是PPP协议的一种扩展,它将PPP帧封装进IP包中,通过IP网络进行传输.它通过PPTP控制连 ...

  9. linux下使用yum安装Apache+php+Mysql+phpMyAdmin

    适用redhat于32位及64位,前提架设好本地源.在这里不再赘述. 1 安装Apache+php+Mysql a.安装Apahce, PHP, Mysql, 以及php连接mysql库组件 yum ...

  10. 正则匹配中 ^ $ 和 \b 的区别

    正则匹配中 ^ $ 和 \b 的区别     ^和$分别代表字符串的开始和结束,因此^\d$只能匹配包含一个数字的字符串\b代表单词边界,其前后必须是不同类型的字符,可以组成单词的字符为一种类型,不可 ...