Home  >  Article  >  Backend Development  >  python uses function to output fields

python uses function to output fields

silencement
silencementOriginal
2019-06-05 15:46:0955865browse

python uses function to output fields

There are two ways to use python to output the field grid:

The first one uses the print function

The code is as follows

print("+-----+-----+")
print("+     +     +")
print("+     +     +")
print("+     +     +")
print("+-----+-----+")
print("+     +     +")
print("+     +     +")
print("+     +     +")
print("+-----+-----+")

Output result

python uses function to output fields

The second type uses loop output

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)))

Output result

python uses function to output fields

The above is the detailed content of python uses function to output fields. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn