python打印等腰三角形_Python 打印各种三角形

  • Post author:
  • Post category:python


直角三角形

rows = int(input(‘输入列数:’))

for i in range(1, rows):

print(‘*’ * i)

for i in range(1, rows):

for j in range(i):

print(“*”, end=””)

print(“”)

等腰直角三角形

rows = int(input(‘输入列数:’))

for i in range(1, rows):

print(‘ * ‘ * i)

for i in range(1, rows):

for j in range(1, i + 1):

print(” * “, end=””)

print(“”)

打印等腰三角形

rows = int(input(‘输入列数:’))

for i in range(1, rows):

if i % 2 != 0:

str = (‘*’ * i)

print(str.center(9, ‘ ‘))

正方形

rows = int(input(‘输入列数:’))

for i in range(0, rows):

print(” * ” * rows)

for i in range(0, rows):

for j in range(0, rows):

print(” * “, end=””)<