5 Best Python difficult Pattern Programs

5 Best Python difficult Pattern Programs

In this lesson, I show you how to print patterns in Python. The following Python programs use for loops, By printing different patterns, you can build a solid understanding of loops in Python

What is a pattern program in Python?

Patterns can be printed in python using simple for loops. The first outer loop is used to handle the number of rows and the Inner nested loop is used to handle the number of columns. Manipulating the print statements, different number patterns, alphabet patterns, or star patterns can be printed.

This article let you know how to print the following patterns in Python

1 Star And Number Mixed

n = 5
for x in range(1,n+1):
    for y in range(n,0,-1):
        if y>x:
            print("*", end="")
        else:
            print(x, end="")
    print()

2 Star And Alphabets Mixed

n = 5
for x in range(0,n):
    for y in range(0,n):
        if y>x:
            print("*", end="")
        else:
            print(chr(y+65), end="")
    print()

3 Heart Pattern

n = 5 # size 

# Upper Part 
for x in range(n//2,n+1,+2): 
    for y in range(1,n-x,+2): 
        print(" ",end="") 
    for y in range(1,x+1): 
        print("*", end="") 
    for y in range(1,n-x+1): 
        print(" ",end="") 
    for y in range(1,x+1): 
        print("*",end="") 
    print() 

# Lower Part 
for x in range(n,0,-1): 
    for y in range(x,n): 
        print(" ",end="") 
    for y in range(1,(x*2)): 
        print("*",end="") 
    print()

4 Your Name Half-Pyramid

name = "AMIT"
strlen = len(name)

for x in range(0, strlen):
    print(name[0:x+1])

5 Number and Alphabets Half-Pyramid

n = 5
for x in range(1,n+1):
    for y in range(1,x+1):
        if(x%2==0):
            print(chr(y+64), end="")
        else:
            print(y, end="")
    print()

Get Daily New Pattern Program Follow This Page Click here

Alright, guys! I hope this article was helpful for you if you leave your comments below. I will meet you in another article until then KEEP CODING 🛸.

Did you find this article valuable?

Support Amit Gajare by becoming a sponsor. Any amount is appreciated!