
用python输出田字格,有两种办法:
第一种使用print函数
代码如下
print("+-----+-----+")
print("+ + +")
print("+ + +")
print("+ + +")
print("+-----+-----+")
print("+ + +")
print("+ + +")
print("+ + +")
print("+-----+-----+")输出结果
立即学习“Python免费学习笔记(深入)”;

第二种使用循环输出
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用函数输出田字格的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号