本文摘自php中文网,作者silencement,侵删。

用python输出田字格,有两种办法:
第一种使用print函数
代码如下
1 2 3 4 5 6 7 8 9 | print("+-----+-----+")
print("+ + +")
print("+ + +")
print("+ + +")
print("+-----+-----+")
print("+ + +")
print("+ + +")
print("+ + +")
print("+-----+-----+")
|
输出结果

第二种使用循环输出
1 2 3 4 5 6 7 8 9 10 11 | n = eval(input(“请输入一个奇数:”))
a = “-”
b = “┼”
c = “∣”
d = " "
m = n // 2
for i in range(n):
if i in [0,m,n-1]:
print("{0}{1}{0}{1}{0}".format(b,a*(m-1)))
else:
print("{0}{1}{0}{1}{0}".format(c,d2(m-1)))
|
输出结果

以上就是python用函数输出田字格的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
解决pycharm找不到解释器的问题
Python如何调用api接口
Python语句中pass语句有什么作用?浅谈pass语句的用法
Python运算符-编程中最常用的比较运算符(实例解析)
Python2.7中关于sqlite3基本操作的示例详解
django admin源码的分析(附示例)
介绍Python中slice参数过长的处理方法及实例
Python中字典如何排序
Python语言变量命名规则
Python代码的单行注释使用什么符号
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python用函数输出田字格