Introduction
In this blog, I will show you a Python Pattern Program that will use a collection of stars and words to create and display a heart shape.
Simple heart shape using Python
Here, we will create a pattern program to display an outline of a heart shape with stars using Python IDLE.
Source code
- for row in range(6):
- for col in range(7):
- 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()
- The first for loop is used to display six lines of row stars.
- Then, the second for loop performs to display some columns in the heart shape.
- The "if-else" condition is performed to do an actual determination of heart shape.
- The first and second statements inside of the IF parameter can display stars as a horizontal line of the top two lines (four-star and three-star) of heart shape.
- Next, the remaining two parameters of IF expression can be displayed stars as the right to left and left to right of the heart shape.
Output