Python Program to Print K Shape Alphabets Pattern

Write a Python program to print K shape alphabets pattern using for loop.

rows = int(input("Enter K Shape Alphabets Pattern Rows = "))

print("====K Shape Alphabets Pattern====")

for i in range(rows, 0, -1):
    alphabet = 65
    for j in range(0, i):
        print('%c' %(alphabet + j), end = ' ')
    print()

for i in range(1, rows):
    alphabet = 65
    for j in range(0, i + 1):
        print('%c' %(alphabet + j), end = ' ')
    print()
Python Program to Print K Shape Alphabet Pattern

This Python example prints the alphabets arranged in K shape pattern using a while loop.

rows = int(input("Enter K Shape Alphabets Pattern Rows = "))

print("====K Shape Alphabets Pattern====")

i = rows - 1
while(i >= 0):
    alphabet = 65
    j = 0
    while(j <= i):
        print('%c' %(alphabet + j), end = ' ')
        j = j + 1
    print()
    i = i - 1

i = 1
while(i < rows):
    alphabet = 65
    j = 0
    while(j <= i):
        print('%c' %(alphabet + j), end = ' ')
        j = j + 1
    print()
    i = i + 1
Enter K Shape Alphabets Pattern Rows = 8
====K Shape Alphabets Pattern====
A B C D E F G H 
A B C D E F G 
A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F 
A B C D E F G 
A B C D E F G H 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.