Inverted 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 inverted V (one star on top, then two stars farther apart each row). See Program 8 for the upright V (wide row first, vertex at the bottom).

Each row starts with spaces to shift the left edge, then one star; from row 2 onward, an inner gap of 2 * i - 3 (growing by 2 each row) and a second 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(1, rows + 1):
    print(" " * (rows - i), end="")
    print("*", end="")

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

    print()

🧠 How It Works

1

Setup

rows sets the height. for i in range(1, rows + 1): walks from the apex to the wide base. Each row is built with print(..., end="") pieces, then print() finishes the line.

Setup
2

Left margin and first star

print(" " * (rows - i), end="") shifts the row right. print("*", end="") draws the left leg of the V.

Left leg
3

Gap and right star (when i > 1)

if i > 1: then print(" " * (2 * i - 3), end="") hollows the interior (gap width grows by 2 per row), and print("*", end="") places the right leg. Row 1 skips this block so you get a single apex star.

Right leg
4

Finish the line

print() adds the newline. Each row has width 2 * rows - 1 characters (padding + stars + interior spaces).

Line break
=

Hollow inverted V

O(n²) output for n = rows, O(1) extra space. Width 2n - 1 scrolls inside the green preview on phones.

2

Variation — User Input Version

Read rows from user input:

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

for i in range(1, rows + 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)
  • Print the V-shaped hollow half next (Program 8) to form a diamond (Program 9)
  • Replace * with other characters like #
  • Use string-building to create each row, then print once per line
  • Print a filled V by printing stars instead of spaces in the inner gap

Avoid

  • Printing the second star on the first 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

Each row prints one left edge star and (except the first row) one right edge star.

2

Leading spaces are rows - i to position the left edge.

3

Inner gap is 2 * i - 3, growing by 2 each row.

4

Total printed characters per row are \(\Theta(rows)\), so total time is O(rows²).

5

This pattern is the upper half of a hollow diamond (Program 9).

❓ Frequently Asked Questions

At the top tip, both edges meet at the same position, so you print a single star.
Instead of printing spaces for the inner gap, print stars (or another character). That fills the inside.
It’s O(n²) for n rows: there are \(n\) lines and each line prints \(\Theta(n)\) characters.

Next: V-Shaped Hollow

Continue to Program 8 to print the upright V-shaped hollow pattern and complete a hollow diamond in Program 9.

Program 8 →
Did you know?

This pattern is a building block for hollow diamonds: add the V-shaped half (Program 8) below it to form Program 9.

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