Print Ganesha Pattern Program In Python

Print Ganesha Pattern Program In Python

Print Ganesha Pattern Program In Python

This tutorial on printing the Ganesha pattern in Python programming involves basic programming.

Prerequisite:

You don’t need any fancy Python library. It is a play of simple logic.

Print Ganesha Pattern Program In Python

# Print Ganesha Crown
for i in range(1,5):
    for j in range(i,9):
        print(" ", end='')
    for k in range((2*i)-1):
        print("*",end='')
    print()

# Print Ganesha Ear and Mouth
for i in range(4):
    for j in range(i):
        print(" ",end='')
    for j in range(i,4):
        print("#",end='')
    for j in range(1, 8):
        if(j == 1):
            print(" @", end='')
        elif (j == 7):
            print("@ ", end='')
        else:
            print("@",end='')
    for j in range(i, 4):
        print("#",end='')
    print()

# Print Ganesha trunk
for i in range(2):
    for j in range(7):
        print(" ", end="")
    for j in range(4):
        print("@", end="")
    print()

# Print Ganesha next trunk
for i in range(3):
    for j in range(i+8):
        print(" ",end='')
    for k in range(3):
        print("@", end="")
    print()

# Print Ganesha next trunk
for i in range(2):
    for j in range(i+11):
        print(" ", end="")
    for k in range(2):
        print("@", end="")
    print()

# Print Ganesha last single trunk
for j in range(14):
    print(" ", end="")
print("@")

Try executing the Python program above and you will see the Ganesha pattern printed.

Output:

print Ganesha pattern in Python code

You can tweak the range value in the for-loop to make your Ganesha big or small. Happy Ganesha!

Leave a Reply

Your email address will not be published. Required fields are marked *