Python program to print the Inverted heart pattern

04 Oct, 2021
Let us see how to print an inverted heart pattern in Python.
Example:
Input: 11
Output:

          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
*********************
 *********  ********
  *******    ******
   *****      **** 
   
Input: 15
Output:
              *
             ***
            *****
           *******
          *********
         ***********
        *************
       ***************
      *****************
     *******************
    *********************
   ***********************
  *************************
 ***************************
*****************************
 *************  ************
  ***********    **********
   *********      ********
    *******        ******
Approach:
Determine the size of the heart.Print an inverted triangle with size number of rows.Print the rest of the heart in 4 segments inside another loop.Print the white space right-triangle at the beginning.Print the first trapezium with stars.Print the white space triangle.Print the second trapezium with stars.
Determine the size of the heart.
Print an inverted triangle with size number of rows.
Print the rest of the heart in 4 segments inside another loop.
Print the white space right-triangle at the beginning.
Print the first trapezium with stars.
Print the white space triangle.
Print the second trapezium with stars.
Python3
# determining the size of the heartsize = 15 # printing the inverted trianglefor a in range(0, size):    for b in range(a, size):        print(" ", end = "")    for b in range(1, (a * 2)):        print("*", end = "")    print("") # printing rest of the heartfor a in range(size, int(size / 2) - 1 , -2):     # printing the white space right-triangle    for b in range(1, size - a, 2):         print(" ", end = "")     # printing the first trapezium    for b in range(1, a + 1):        print("*", end = "")     # printing the white space triangle    for b in range(1, (size - a) + 1):        print(" ", end = "")     # printing the second trapezium    for b in range(1, a):        print("*", end = "")     # new line    print("")
Output:
              *
             ***
            *****
           *******
          *********
         ***********
        *************
       ***************
      *****************
     *******************
    *********************
   ***********************
  *************************
 ***************************
*****************************
 *************  ************
  ***********    **********
   *********      ********
    *******        ******
 
anikakapoor
pattern-printing
Python Pattern-printing
Python
Python Programs
pattern-printing
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python Program for Fibonacci numbers
Python | Split string into list of characters