Python Program to Print T Star Pattern

This article shows how to write a Python program to print the Alphabet T star pattern using the for loop, while loop, and functions with an example. 

The T-star pattern example below accepts the user-entered rows, and the nested for loop iterates over the rows. The Python If else condition is used to print stars at the first row and the middle column to get the Alphabetical T pattern of stars and skip the others.

rows = int(input("Enter Alphabet T of Stars Rows = "))
print("====The Alphabet T Star Pattern====")

for i in range(rows):
    for j in range(rows):
        if i == 0 or j == rows // 2:
            print("*", end=" ")
        else:
            print(" ",end=" ")
    print()
Program to Print Alphabetical T Star Pattern

Python program to print the Alphabet T Star pattern using while loop

Instead of a For loop, this program uses a while loop to iterate the Alphabet T pattern rows and print the stars on the first row and the middle column. For more, check the Python Star Pattern programs.

rows = int(input("Enter Alphabet T of Stars Rows = "))

i = 0
while i < rows:
    j = 0
    while j < rows:
        if i == 0 or j == rows // 2:
            print("*", end=" ")
        else:
            print(" ",end=" ")
        j += 1
    print()
    i += 1
Enter Alphabet T of Stars Rows = 11
* * * * * * * * * * * 
          *           
          *           
          *           
          *           
          *           
          *           
          *           
          *           
          *           
          *      

In this Python example, we created a TPattern function that accepts the rows and the symbol or character. Next, it prints the Alphabet T pattern of the given symbol.

def TPattern(rows, ch):
for i in range(rows):
for j in range(rows):
if i == 0 or j == rows // 2:
print('%c' %ch, end=' ')
else:
print(" ", end=" ")
print()


row = int(input("Enter Rows = "))
sy = input("Symbol for T Star Pattern = ")
TPattern(row, sy)
Enter Rows = 13
Symbol for T Star Pattern = $
$ $ $ $ $ $ $ $ $ $ $ $ $ 
            $             
            $             
            $             
            $             
            $             
            $             
            $             
            $             
            $             
            $             
            $             
            $     

Also Read