Home > Article > Backend Development > 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
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
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!