Program to Print K using Alphabets

Python provides various ways to create letter patterns using text characters. The letter K can be printed using different approaches and alphabets from the English language.

Method 1: Using 'K' Character with Mathematical Logic

This approach uses mathematical conditions to determine where to place the 'K' character ?

string = ""  
j = 7
i = 0	

for Row in range(0, 10):    
    for Col in range(0, 10):     
        if (Col == 1 or ((Row == Col + 1) and Col != 0)):  
            string = string + "K"    
        elif (Row == i and Col == j):  
            string = string + "K"    
            i = i + 1  
            j = j - 1  
        else:      
            string = string + " "    
    string = string + "\n"    

print(string)
 K       K
 K      K 
 K     K  
 K    K   
 K   K    
 KK K     
 K K      
 K  K     
 K   K    
 K    K   

Method 2: Using Simple Print Statements

This method uses a function with predefined 'A' character patterns ?

def print_k():
    print("A   A")
    print("A  A ")
    print("A A  ")
    print("AA   ")
    print("A A  ")
    print("A  A ")
    print("A   A")

print_k()
A   A
A  A 
A A  
AA   
A A  
A  A 
A   A

Method 3: Using ASCII Characters

This approach creates a K-like pattern using different ASCII characters in a triangular formation ?

def display(n):
    val = n
    
    # Upper part - decreasing pattern
    while (val >= 0):
        c = 80  # ASCII value for 'P'
        for j in range(val + 1):
            print(chr(c + j), end=" ")
        val = val - 1
        print()
    
    # Lower part - increasing pattern
    for i in range(n + 1):
        c = 100  # ASCII value for 'd'
        for j in range(i + 1):
            print(chr(c + j), end=" ")
        print()

n = 8
display(n)
P Q R S T U V W X 
P Q R S T U V W 
P Q R S T U V 
P Q R S T U 
P Q R S T 
P Q R S 
P Q R 
P Q 
P 
d 
d e 
d e f 
d e f g 
d e f g h 
d e f g h i 
d e f g h i j 
d e f g h i j k 
d e f g h i j k l 

Comparison

Method Character Used Approach Best For
Mathematical Logic 'K' Grid-based positioning Precise K shape
Simple Print 'A' Direct output Quick implementation
ASCII Characters Various letters Character sequences Creative patterns

Conclusion

Python offers multiple ways to create letter K patterns. Use mathematical logic for precise shapes, simple print statements for quick results, or ASCII characters for creative variations.

Updated on: 2026-03-27T15:59:18+05:30

406 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements