python打印*练习

#打印*

输入5
*
**
***
****
*****
a =int(input("输入:"))
for i in range(1,a+1):
    for j in range(i):
        print("*",end = "")
    print()

    
输入5
*
***
*****
*******
*********
a =int(input("输入:"))
for i in range(a):
    for j in range(2*i+1):
            print("*",end = "") 
    print()
        
a =int(input("输入:"))
for i in range(1,a+6):
    for j in range(0,i):
        if i%2!=0:
            print("*",end = "")
            
    if i%2==0:   
        print()

        
输入5
    *
   **
  ***
 ****
*****        
#倒直角
a =int(input("输入:"))
for i in range(1,a+1):
    print(" "*(a-i),end ="")
    print("*"*i)

for i in range(, ,):      

输入5
    *
   ***
  *****
 *******
*********
#等腰
a =int(input("输入:"))

for i in range(1,a + 1):#打印空格
    for j in range( a- i):
        print(" ", end="")#打印*的个数
    for j in range(2 * i - 1):
        print("*", end="")
    print()


输入5
*********
 *******
  *****
   ***
    * 
a =int(input("输入:"))
#倒等腰
for i in range(a,0 ,-1):#打印空格
    for j in range( a- i):
        print(" ", end="")#打印*的个数
    for j in range(2 * i - 1):
        print("*", end="")
    print()    



输入奇数行11
          *
         ***
        *****
       *******
      *********
     ***********
      *********
       *******
        *****
         ***
          *

#菱形
a =int(input("输入奇数行:"))
while a%2==0:
    a=int(input("输入奇数行:"))
#上半
for i in range(1,a//2 + 1):#打印空格:
        print(" "*(a-i), end="")#打印*的个数
        print("*"*(2 * i - 1))
#下半
for i in range(a//2+1,0 ,-1):#打印空格
        print(" "*( a- i), end="")#打印*的个数
        print("*"*(2 * i - 1))


输入奇数行11
          *
         * *
        *   *
       *     *
      *       *
     *         *
      *       *
       *     *
        *   *
         * *
          *
#空心菱形
a =int(input("输入奇数行:"))
while a%2==0:
    a=int(input("输入奇数行:"))
#上半
for i in range(1,a//2 + 1):#打印空格:
        print(" "*(a-i), end="")#打印*的个数
        for j in range(2 * i - 1):
            if j==0 or j==(2 * i - 2):
                print("*",end="")
            else:
                print(" ",end="")
        print()
#下半
for i in range(a//2+1,0 ,-1):#打印空格
        print(" "*( a- i), end="")#打印*的个数
        for j in range(2 * i - 1):
            if j==0 or j==(2 * i - 2):
                print("*",end="")
            else:
                print(" ",end="")
        print()

        
输入奇数行5
    *
   ***
  * * *
   ***
    *
a =int(input("输入奇数行:"))
while a%2==0:
    a=int(input("输入奇数行:"))
#上半
for i in range(1,a//2 + 1):#打印空格:
        print(" "*(a-i), end="")#打印*的个数
        for j in range(2 * i - 1):
            if j==0 or j==(2 * i - 2)or j==(i-1)or i==(a//2+1):
                print("*",end="")
            else:
                print(" ",end="")
        print()
#下半
for i in range(a//2+1,0 ,-1):#打印空格
        print(" "*( a- i), end="")#打印*的个数
        for j in range(2 * i - 1):
            if j==0 or j==(2 * i - 2)or j==(i-1) or i==(a//2+1):
                print("*",end="")
            else:
                print(" ",end="")
        print()

你可能感兴趣的:(python,python,算法)