Python Program to Print V Star Pattern

Write a Python program to print V star pattern using for loop.

rows = int(input("Enter V Star Pattern Rows = "))

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

for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print('*', end = '')
    for k in range(1, 2 * (rows - i) + 1):
        print(end = ' ')
    for l in range(1, i + 1):
        print('*', end = '')
    print()
Python Program to Print V Star Pattern

Python program to print the V star pattern of stars using a while loop.

rows = int(input("Enter V Star Pattern Rows = "))

print("====The V Star Pattern====")
i = 1

while(i <= rows):
    j = 1
    while(j <= i):
        print('*', end = '')
        j = j + 1
    k = 1
    while(k <= 2 * (rows - i)):
        print(end = ' ')
        k = k + 1
    l = 1
    while(l <= i):
        print('*', end = '')
        l = l + 1
    print()
    i = i + 1
Enter V Star Pattern Rows = 10
====The V Star Pattern====
*                  *
**                **
***              ***
****            ****
*****          *****
******        ******
*******      *******
********    ********
*********  *********
********************

In this Python example, the vStarPattern function allows entering any character and prints the V pattern of a given character.

def vStarPattern(i, ch):
    for j in range(1, i + 1):
        print('%c' %ch, end = '')
        
rows = int(input("Enter V Star Pattern Rows = "))
ch = input("Symbol to use in V Pattern = " )
print("====The V Star Pattern====")

for i in range(1, rows + 1):
    vStarPattern(i, ch)
    for k in range(1, 2 * (rows - i) + 1):
        print(end = ' ')
    vStarPattern(i, ch)
    print()
Enter V Star Pattern Rows = 15
Symbol to use in V Pattern = $
====The V Star Pattern====
$                            $
$$                          $$
$$$                        $$$
$$$$                      $$$$
$$$$$                    $$$$$
$$$$$$                  $$$$$$
$$$$$$$                $$$$$$$
$$$$$$$$              $$$$$$$$
$$$$$$$$$            $$$$$$$$$
$$$$$$$$$$          $$$$$$$$$$
$$$$$$$$$$$        $$$$$$$$$$$
$$$$$$$$$$$$      $$$$$$$$$$$$
$$$$$$$$$$$$$    $$$$$$$$$$$$$
$$$$$$$$$$$$$$  $$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

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.