python uses function to output fields

silencement
Release: 2019-06-05 15:46:09
Original
55781 people have browsed it

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("+-----+-----+")
Copy after login

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)))
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!