V-Shaped Hollow Star Pattern in Python

Beginner
⏱️ 9 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
2i − 3 inner gap

What You'll Learn

This program prints a hollow V (wide first row, legs meet at the bottom). See Program 7 for the inverted V. It uses for i in range(rows, 0, -1) so the inner gap shrinks by 2 each row.

For each row, print leading spaces, a left edge star, an optional inner gap, and a right edge star.

⭐ Pattern Output

When you run the program with rows = 5:

Output
*       *
 *     *
  *   *
   * *
    *
1

Complete Python Program

Fixed rows = 5 version:

Python
rows = 5

for i in range(rows, 0, -1):
    print(" " * (rows - i), end="")
    print("*", end="")

    if i > 1:
        print(" " * (2 * i - 3), end="")
        print("*", end="")

    print()

🧠 How It Works

1

Setup

for i in range(rows, 0, -1): prints the wide pair of legs first and ends at the bottom vertex. The same print(..., end="") pattern as Program 7 applies; only i’s direction changes.

Setup
2

Left margin and first star

print(" " * (rows - i), end="") then print("*", end=""). As i counts down, rows - i grows, shifting the whole row rightward each time.

Left leg
3

Gap and second star

if i > 1: prints " " * (2 * i - 3) then the second *. When i == 1, only the first star and margin appear—the bottom vertex.

Right leg
4

Finish the line

print() ends each row. Line width stays 2 * rows - 1, same geometry as Program 7 with reversed row order.

Line break
=

Hollow V

Vertex at the bottom, opening upward. O(n²) output for n = rows, O(1) extra space. Wide rows scroll horizontally in the green preview on small screens.

2

Variation — User Input Version

Read rows from user input:

Python
rows = int(input("Enter the number of rows: "))

for i in range(rows, 0, -1):
    print(" " * (rows - i), end="")
    print("*", end="")

    if i > 1:
        print(" " * (2 * i - 3), end="")
        print("*", end="")

    print()

💡 Tips for Enhancement

Try These

  • Validate input (reject rows < 1)
  • Combine with Program 7 to form a hollow diamond (Program 9)
  • Replace * with other characters like #
  • Build each row as a string and print once per line
  • Try printing a filled V by replacing the gap with stars

Avoid

  • Printing the second star on the last row (it duplicates the tip)
  • Mixing tabs and spaces for alignment
  • Forgetting newlines between rows
  • Using the wrong gap formula (it should be 2*i - 3)
  • Assuming user input is always valid

Key Takeaways

1

The pattern is the mirror of Program 7: start wide and shrink toward the bottom vertex.

2

Leading spaces are rows - i.

3

Inner gap is 2 * i - 3 and decreases by 2 each row.

4

Time complexity is O(rows²) because each row prints \(\Theta(rows)\) characters.

5

This pattern forms the lower half of a hollow diamond (Program 9).

❓ Frequently Asked Questions

At the bottom tip, both edges meet, so there’s only one star to print.
Print Program 7 (inverted V, upper half) first, then print Program 8’s loop starting from rows - 1 to avoid duplicating the middle row. That creates Program 9.
It’s O(n²) for n rows: there are \(n\) lines and each line prints \(\Theta(n)\) characters.

Next: Hollow Diamond Pattern

Continue to Program 9 to combine Program 7 and Program 8 into a hollow diamond.

Program 9 →
Did you know?

Starting the lower half from rows - 1 is a common trick to avoid printing the center row twice when building symmetric patterns.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful