Python Heart Shape Star Pattern Program
This Python pattern printing program uses the logic of the following figure. We can see that how the stars are present in certain positions. We will create some conditions on the basis of star posittion in each row.
For example we consider the first row which is zero row. Now zero row has no stars (but space) on position 0,3 and 6. Hence we will create a condition if row==0 and col%3 !=0.
0%3, 3%3 and 6%3 all give 0 as remainder and so a space will be printed at position 0, 3 and 6. A star will be printed otherwise.
Similarly, other conditions are made for remaining row of the heart shape.
# Write a Python program # using nested for loops to print the # heart shape using stars pattern. # ** ** # * * * # * * # * * # * * # * # # Perfect Python Programming Tutorials # Author : www.EasyCodebook.com (c) # Actual Program starts here # Python Program - Heart Shape Star Pattern Program No. 1 n = 6 for row in range(0,n): for col in range(0,n+1): if(row==0 and col%3!=0) or (row==1 and col%3==0) or (row-col==2) or (row+col==8): print('*',end='') else: print(' ',end='') print()
Output
** ** * * * * * * * * * *
You may also like:
- C Program Print Heart Shape Star Pattern
- Python Star Pattern Row 1 to 5 Triangle
- C ++ Program Alphabet Triangle Pattern
- Python Program Print Star Pattern 6
- Python Program Print Star Pattern 5
- Python Program Print Star Pattern 4
- Python Program Print Star Pattern 3
- Python Star Pattern Program 2
- Python Star Pattern Program 1