All star patterns using Python programming Language


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999



Star pattern : 1

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

  1. for i in range(0, 5):
  2. for j in range(0, i+1):
  3. print("* ",end="")
  4. print()

Star pattern : 2

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

  1. k = 1
  2. for i in range(0, 5):
  3. for j in range(0, k):
  4. print("* ", end="")
  5. k = k + 2
  6. print()

Star pattern : 3

*

* *

* * *

* * * *

* * * * *

  1. k = 8
  2. for i in range(0, 5):
  3. for j in range(0, k):
  4. print(end=" ")
  5. k = k - 2
  6. for j in range(0, i+1):
  7. print("* ", end="")
  8. print()

Star pattern : 4

*

* * *

* * * * *

* * * * * * *

* * * * * * * * *

  1. k = 16
  2. tim = 1
  3. for i in range(0, 5):
  4. for j in range(0, k):
  5. print(end=" ")
  6. k = k - 4
  7. for j in range(0, tim):
  8. print("* ", end="")
  9. tim = tim + 2
  10. print()
  11.  

     


Star pattern 5

*

***

*****

*******

*********

  1. k = 0
  2. rows = 5
  3. for i in range(1, rows+1):
  4. for space in range(1, (rows-i)+1):
  5. print(end=" ")
  6. while k != (2*i-1):
  7. print("* ", end="")
  8. k = k + 1
  9. k = 0
  10. print()
  11.  

Star pattern 6

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

  1. for i in range(0, 5):
  2. for j in range(5, i, -1):
  3. print("* ", end="")
  4. print()

Star pattern 7

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

  1. n=5;
  2. for i in range(n):
  3. for j in range(i):
  4. print ('* ', end="")
  5. print('')
  6.  
  7. for i in range(n,0,-1):
  8. for j in range(i):
  9. print('* ', end="")
  10. print('')
  11.  

Star pattern 8

*

***

*****

*******

*********

*******

*****

***

*

  1. n=5;
  2. for i in range(0,n+1):
  3. for j in range(0,n-i):
  4. print(end=" ")
  5. for j in range(0,i):
  6. print("*",end=" ")
  7. print()
  8. if i==n:
  9. for i in range(n-1,0,-1):
  10. for j in range(0,n-i):
  11. print(end=" ")
  12. for j in range(0,i):
  13. print("*",end=" ")
  14. print()
  15.  

Star pattern 9

* * * * *

* * * *

* * *

* *

*

  1. for e in range (5,0,-1):
  2. print((5-e) * ' ' + e * '*')
  3.  

Star pattern 10

*

* *

* * *

* * * *

* * * * *

  1. for g in range (6,0,-1):
  2. print(g * ' ' + (6-g) * '*')
  3.  

Star pattern 11

*

**

**

**

*********

  1. for row in range(1,5):
  2. for col in range(1,8):
  3. if (row==4 or row+col==5 or col-row==3):
  4. print("*",end="")
  5. else:
  6. print(" ",end="")
  7. print()
  8.  

Star pattern 12

* * * * *

**

**

**

*

  1. n=5;
  2. for r in range(0,n):
  3. for c in range(0,n):
  4. if r==0 or c==(n-1) or r==c:
  5. print("*",end="")
  6. else:
  7. print(end=" ")
  8. print()
  9.  

Star pattern 13 : 'A' Pattern in Python

 
  ***
 *   *
 *   *
 *****
 *   *
 *   *
 *   *
  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (((column == 1 or column == 5) and row != 0) or ((row == 0 or row == 3) and (column > 1 and column < 5))):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);

Star pattern 14 : 'D' Pattern in Python

 
 **** 
 *   *
 *   *
 *   *
 *   *
 *   *
 **** 
  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (column == 1 or ((row == 0 or row == 6) and (column > 1 and column < 5)) or (column == 5 and row != 0 and row != 6)):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);
  10.  

Star pattern 15 : 'E' Pattern in Python

 
 *****
 *
 *
 ****
 *
 *
 *****
  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (column == 1 or ((row == 0 or row == 6) and (column > 1 and column < 6)) or (row == 3 and column > 1 and column < 5)):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);
  10.  

Star pattern 16 : 'G' Pattern in Python

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

  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if ((column == 1 and row != 0 and row != 6) or ((row == 0 or row == 6) and column > 1 and column < 5) or (row == 3 and column > 2 and column < 6) or (column == 5 and row != 0 and row != 2 and row != 6)):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);
  10.  

Star pattern 17 : 'L' Pattern in Python

 
*
*
*
*
*
*
*****
  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (column == 1 or (row == 6 and column != 0 and column < 6)):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);
  10.  

Star pattern 18 : 'M' Pattern in Python


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

  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (column == 1 or column == 5 or (row == 2 and (column == 2 or column == 4)) or (row == 3 and column == 3)):
  5. result_str=result_str+"* "
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);

Star pattern 19 : 'O' Pattern in Python

  ***
 *   *
 *   *
 *   *
 *   *
 *   *
  ***
  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (((column == 1 or column == 5) and row != 0 and row != 6) or ((row == 0 or row == 6) and column > 1 and column < 5)):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);
  10.  

Star pattern 20 : 'P' Pattern in Python

 ****
 *   *
 *   *
 ****
 *
 *
 *
  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (column == 1 or ((row == 0 or row == 3) and column > 0 and column < 5) or ((column == 5 or column == 1) and (row == 1 or row == 2))):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);
  10.  

Star pattern 21 : 'X' Pattern in Python

 *   *
 *   *
  * *
   *
  * *
 *   *
 *   *
  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (((column == 1 or column == 5) and (row > 4 or row < 2)) or row == column and column > 0 and column < 6 or (column == 2 and row == 4) or (column == 4 and row == 2)):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);
  10.  

Star pattern 22 : 'Z' Pattern in Python

*******
     *
    *
   *
  *
 *
*******
  1. result_str="";
  2. for row in range(0,7):
  3. for column in range(0,7):
  4. if (((row == 0 or row == 6) and column >= 0 and column <= 6) or row+column==6):
  5. result_str=result_str+"*"
  6. else:
  7. result_str=result_str+" "
  8. result_str=result_str+"\n"
  9. print(result_str);



Related Topics




Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.