Python 打印各种三角形

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 打印各种三角形相关的知识,希望对你有一定的参考价值。

参考技术A

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="")
print(" ")

for x in range(10):
for i in range(x, 10):
print(\'*\', end=\'\')
print(\'\')

print(\'同一行打印直角三角形\')
for j in range(10):
for x in range(0, j):
print(\' \', end=\'\')
for n in range(j, 19 - j):
print(\' \', end=\'\')
for k in range(0, j):
print(\'
\', end=\'\')
print(\'\')

print(\'直角三角形拼装心形\')
for j in range(8):
for x in range(0, j):
print(\' \', end=\'\')
for n in range(j, 19 - j):
print(\' \', end=\'\')
for k in range(0, j):
print(\'
\', end=\'\')
print(\'\')
for i in range(10):
for j in range(0, 0 + i):
print(end=\' \')
for k in range(0 + i, 10):
print(\'*\', end=\' \')
print(\'\')

print(\'打印倒立等腰三角形1\')
for j in range(10):
for x in range(0, j):
print(end=\' \')
for n in range(j, 15 - j):
print(\'*\', end=\'\')

print(\'打印倒立等腰三角形2\')
for i in range(10):
for j in range(0, 0 + i):
print(end=\' \')
for k in range(0 + i, 10):
print(\'*\', end=\' \')
print(\'\')

print(\'同一行打印两个等腰三角形\')
for i in range(10):
for j in range(0, 10 - i):
print(end=\' \')
for k in range(10 - i, 10):
print(\' \', end=\' \')
for n in range(0, 0):
print(end=\' \')
for m in range(0 + i, 10):
print(\' \', end=\' \')
for jj in range(10, 10):
print(end=\' \')
for kk in range(10 - i, 10):
print(\'
\', end=\' \')
print(\'\')

print(\'等腰三角形拼装心形\')
for i in range(10):
for j in range(0, 10 - i):
print(end=\' \')
for k in range(10 - i, 10):
print(\' \', end=\' \')
for n in range(0, 0):
print(end=\' \')
for m in range(0 + i, 10):
print(\' \', end=\' \')
for jj in range(10, 10):
print(end=\' \')
for kk in range(10 - i, 10):
print(\'
\', end=\' \')
print(\'\')
for i in range(20):
for j in range(0, 0 + i):
print(end=\' \')
for k in range(0 + i, 20):
print(\'*\', end=\' \')
print(\'\')

print(\'打印正方形\')
for i in range(10):
for j in range(0, 10 - i):
print(end=\' \')
for n in range(0, 0 + i):
print(end=\' \')
for m in range(0 + i, 10):
print(\' \', end=\' \')
for k in range(10 - i, 10):
print(\'
\', end=\' \')
print(\'\')

python打印各种三角形

1、打印等边三角形

for i in range(0,5):
    for y in range(0,5-i):
        w =  
        print(w,end="")
    s = *  * i
    print(s)

  打印结果:

    * 
   * * 
  * * * 
 * * * * 

 

2、打印直角三角形

for i in range(10):
    print(**i)

  打印结果:

    *
    **
    ***
    ****

for i in range(0,5):
    for y in range(5-i):
        w =  
        print(w,end=‘‘)
    print(** i)

  打印结果:

      *
     **
    ***
   ****

   







以上是关于Python 打印各种三角形的主要内容,如果未能解决你的问题,请参考以下文章

Python 打印各种三角形

Python中使用循环语句打印三角形菱形

python打印杨辉三角的两种方法及详解

JavaScript-页面打印正方形,各种三角形与菱形

打印各种图案~

打印各种图案~