Python打印各种图形

一、打印直角三角形

*
**
***
****
*****

 

for i in range(1,6):
    print("*"*i,end="\n")

二、打印矩形

* * * * * 
* * * * * 
* * * * * 
* * * * * 
* * * * * 

num = 5
for i in range(1,6):
    print("* "*5)


for n in range(5):
    for i in range(5):
        print("*",end=" ")
    print()

 三、打印直角三角形


* * 
* * * 
* * * * 
* * * * * 

for i in range(5):
    for j in range(i+1):
        print("*",end=" ")
    print()

 四、打印反向直角三角形

        * 
      * * 
    * * * 
  * * * * 
* * * * * 

 

for i in range(5):
    for j in range(4-i):
        print(" ",end=" ")
    for n in range(i+1):
        print("*",end=" ")

    print()

五、打印等边三角形

for i in range(5):
    for j in range(4-i):
        print(" ",end=" ")
    for n in range(i+1):
        print("*  ",end=" ")

    print()

 六、打印变形三角形

* * * * * 
  * * * * 
    * * * 
      * * 
        * 
        * 
      * * 
    * * * 
  * * * * 
* * * * * 

for i in range(5):
    for j in range(i):
        print(" ",end=" ")
    for n in range(5-i):
        print("*",end=" ")
    print()
for i in range(5):
    for j in range(4-i):
        print(" ",end=" ")
    for n in range(i+1):
        print("*",end=" ")
    print()

 七、打印变形三角形


* * 
* * * 
* * * * 
* * * * * 
* * * * 
* * * 
* * 

 

for i in range(10):
    if i <=5:
        for j in range(i):
            print("*",end=" ")
    else:
        for n in range(10-i):
            print("*",end=" ")
    print()

 思路: 通过循环,外层循环控制行数,内层循环控制每行的显示,复制的图形,进行拆分为简单的图形,进行显示

你可能感兴趣的:(Python,python,开发语言,numpy)