Python Program for Printing Hollow Left Pascal’s Star Triangle

Posted by

<!DOCTYPE html>

Python Program to Print Hollow Left Pascals Star Triangle

Python Program to Print Hollow Left Pascal’s Star Triangle

This program prints a hollow left Pascal’s star triangle using Python.

def print_triangle(n):
    for i in range(n):
        for j in range(n):
            if i == j or j == 0:
                print("*", end="")
            elif i==n-1:
                print("*", end="")
            else:
                print(" ", end="")
        print()

n = 5
print_triangle(n)
    

Output:

*
**
* *
*  *
*****
    

This program uses nested loops to iterate through each row and column of the triangle. It prints a star if the conditions are met, otherwise it prints a space. The triangle is hollow on the left side and forms a Pascal’s triangle pattern.

Feel free to run this program in your Python environment and experiment with different values of n to generate different triangle patterns.

0 0 votes
Article Rating

Leave a Reply

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x