fewf
# 打印各种图形
# 正方形 n行n列
# * * *
# * * *
# * * *
def square1(n: int) -> None:
for i in range(n):
for j in range(n):
print('*', end=' ')
print()
# 长方形 n行n+2列
# * * * * *
# * * * * *
# * * * * *
def square2(n: int) -> None:
for i in range(n):
for j in range(n + 2):
print('*', end=' ')
print()
# 平行四边形 n行n+2列
# * * *
# * * *
# * * *
def square3(n: int) -> None:
for i in range(n):
for j in range(n - i - 1):
print(' ', end=' ')
for k in range(n):
print('*', end=' ')
print()
# 上三角 n行2n-1列
# *
# * * *
# * * * * *
def top_sanjiao(n: int) -> None:
for i in range(n):
for j in range(n - i - 1):
print(' ', end=' ')
for k in range(2 * i + 1):
print('*', end=' ')
print()
# 下三角 n行2n-1列
# * * * * *
# * * *
# *
def under_sanjiao(n: int) -> None:
for i in range(n - 1, -1, -1): # 倒序输出:n-1,n-2,...,1,0
for j in range(n - i - 1):
print(' ', end=' ')
for k in range(2 * i + 1):
print('*', end=' ')
print()
# 左三角 n行2n-1列 n必须是奇数
# *
# * *
# * * *
# * *
# *
def left_sanjiao(n: int) -> None:
n = n // 2 + 1 # 类似四舍五入
# 上部分
for i in range(n):
for j in range(n - i - 1):
print(' ', end=' ')
for k in range(i + 1):
print('*', end=' ')
print()
# 下部分
n = n - 1
for i in range(n - 1, -1, -1):
for j in range(n - i):
print(' ', end=' ')
for k in range(i + 1):
print('*', end=' ')
print()
# 右三角 n行2n-1列 n必须是奇数
# *
# * *
# * * *
# * *
# *
def right_sanjiao(n: int) -> None:
n = n // 2 + 1
# 上部分
for i in range(n):
for k in range(i + 1):
print('*', end=' ')
print()
# 下部分
n = n - 1
for i in range(n - 1, -1, -1):
for k in range(i + 1):
print('*', end=' ')
print()
# 直角三角形n行n列
# *
# * *
# * * *
def left_zhijiao(n: int) -> None:
for i in range(n):
for j in range(i + 1):
print('*', end=' ')
print()
# 直角三角形n行n列
# *
# * *
# * * *
def right_zhijiao(n: int) -> None:
for i in range(n):
for j in range(n - i - 1):
print(' ', end=' ')
for k in range(i + 1):
print('*', end=' ')
print()
# 直角三角形n行n列
# * * *
# * *
# *
def bottle_zhijiao(n: int) -> None:
for i in range(n):
for j in range(i):
print(' ', end=' ')
for k in range(n - i):
print('*', end=' ')
print()
# 直角三角形n行n列
# * * *
# * *
# *
def top_zhijiao(n: int) -> None:
for i in range(n):
for j in range(n - i):
print('*', end=' ')
print()
# 菱形 n行n列 n只能是奇数
# *
# * * *
# * * * * *
# * * *
# *
def lingxing(n: int) -> None:
n = n // 2 + 1 # 等效四舍五入
# 上部分
for i in range(n):
for j in range(n - i - 1):
print(' ', end=' ')
for k in range(2 * i + 1):
print('*', end=' ')
print()
# 下部分
n = n - 1
for i in range(n - 1, -1, -1): # 倒序n-1, n-2, ..., 1, 0
for j in range(n - i):
print(' ', end=' ')
for k in range(2 * i + 1):
print('*', end=' ')
print()
标签:None,end,python,打印,int,range,print,图形,def
From: https://www.cnblogs.com/liqiju/p/17290770.html