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
  1. for row in range(6):
  2. for col in range(7):
  3. if (row==0 and col %3 !=0)or(row==1 and col %3==0) or(row-col==2) or(row+col==8):
  4. print("*",end=" ")
  5. else:
  6. print(end=" ")
  7. print()
Source description
  • 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