Python Program to Print W Star Pattern

Write a Python program to print W star pattern using for loop. In this Python code, the printStars function iterate and prints the stars, and the printSpaces prints the spaces to print the W shape.

def printStars(rows):
    for i in range(rows):
        print('*', end = '')

def printSpaces(rows):
    for i in range(rows):
        print(end = ' ')
        
rows = int(input("Enter W Star Pattern Rows = "))

print("====The W Star Pattern====")

for i in range(rows):
    printStars(i + 1)
    printSpaces(rows - i - 1)
    printStars(rows - i + 1)
    printSpaces(2 * i)
    printStars(rows - i)
    printSpaces(rows - i - 1)
    printStars(i + 1);
    print()
Python Program to Print W Star Pattern

In this Python example, both the functions allows entering any character and prints the W pattern of a given character using a while loop.

def printStars(rows, ch):
    i = 0
    while(i < rows):
        print('%c' %ch, end = '')
        i = i + 1

def printSpaces(rows):
    i = 0
    while(i < rows):
        print(end = ' ')
        i = i + 1
        
rows = int(input("Enter W Star Pattern Rows = "))
ch = input("Enter Character for W Pattern = ")
print("====The W Star Pattern====")

i = 0
while(i < rows):
    printStars(i + 1, ch)
    printSpaces(rows - i - 1)
    printStars(rows - i + 1, ch)
    printSpaces(2 * i)
    printStars(rows - i, ch)
    printSpaces(rows - i - 1)
    printStars(i + 1, ch);
    print()
    i = i + 1
Enter W Star Pattern Rows = 14
Enter Character for W Pattern = #
====The W Star Pattern====
#             #############################             #
##            ##############  #############            ##
###           #############    ############           ###
####          ############      ###########          ####
#####         ###########        ##########         #####
######        ##########          #########        ######
#######       #########            ########       #######
########      ########              #######      ########
#########     #######                ######     #########
##########    ######                  #####    ##########
###########   #####                    ####   ###########
############  ####                      ###  ############
############# ###                        ## #############
################                          ###############