#/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. java 调用axis2 webservice

    import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apach ...

  2. 苹果微信input输入框被键盘遮挡

    最近一个项目,input输入框需要在页面的最下面(position:fixed),这样,当键盘获取焦点的时候, 苹果自带键盘不会挡住输入框,但是搜狗输入法的键盘就会挡住.可以用以下方法解决: docu ...

  3. 微信小程序-基础内容组件

    icon 图标 示例: <view class="group"> <block wx:for="{{iconSize}}"> <i ...

  4. Hibernate的性能优化问题

    本文是根据Hibernate帮助文档,以及一些书籍及项目经验整理而成,只提供要点和思路,具体做法可以留言探讨,或是找一些更详细更有针对性的资料. 初用Hibernate的人也许都遇到过性能问题,实现同 ...

  5. kali4.0 更新源出错

    一.前情提要: OS:kail 4.0 64bit 二.出错描述如下: 无法从服务器下载对应版本的软件,我查看了服务器上的版本与我要下载的不一致,因此肯定无法找到对应的软件版本 三.对策: 换源:vi ...

  6. caffe + ubuntu16.04 (version without GPU)

    This Guide is based on caffe github wiki guide (https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-1 ...

  7. pyqt4学习笔记

    信号与槽机制 信号与槽机制作为Qt最重要的特性,提供了任意两个Qt对象之间的通信机制.其中,信号会在某个特定情况或动作下被触发,槽是用于接收并处理信号的函数.例如,要将一个窗口中的变化情况通知给另一个 ...

  8. codeigniter nginx配置

    转载:http://www.nginx.cn/1134.html server{ listen 80; server_name www.ci.oa.com; access_log /usr/local ...

  9. 附加类型的实体失败,因为相同类型的其他实体已具有相同的主键值。在使用 "Attach" 方法或者将实体的状态设置为 "Unchanged" 或 "Modified" 时如果图形中的任何实体具有冲突键值

    var list= DAL.LoadEntities(x => x.OrderCode == orderCode).AsNoTracking().ToList().FirstOrDefault( ...

  10. 【网络】IP地址格式转换(htonl、ntohl;inet_addr、inet_ntoa)

    1.htonl ()和ntohl( ) u_long PASCAL FAR ntohl (u_long netlong); u_short PASCAL FAR ntohs (u_short nets ...