Triangle Star Pattern in Python

Triangle star pattern in Python | We will develop a program to print shapes of triangles using stars.

Python Program to Print Triangle Star Pattern

Triangle Star Pattern-1

Enter number of row: 5
`*`
`* *`
`* * *`
`* * * *`
`* * * * *`

``````# Python star pattern to print left half pyramid

def pattern(n):
for i in range(1, n+1):
# print star
print("* " * i)

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)``````

Triangle Star Pattern-2

Enter number of row: 6
`* * * * * *`
`* * * * *`
`* * * *`
`* * *`
`* *`
`*`

``````# Python star pattern to print downward left half triangle

def pattern(n):
for i in range(n):
# print star
print("* " * (n-i))

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-3

``````Enter number of row: 6

*
* *
* * *
* * * *
* * * * *
* * * * * *
``````
``````# Python star pattern to print right half triangle

def pattern(n):
for i in range(1, n+1):
# print star
print(" " * (n-i) + "*" * i)

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-4

``````Enter number of row: 5

* * * *
* * *
* *
*
``````
``````def pattern(n):
for i in range(n-1):
for j in range(i+1):
print(" ",end=" ")
for k in range(n-i-1):
print("* ",end="")
print()

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-5

``````Enter number of row: 6

*
* *
* * *
* * * *
* * * * *
* * * * * *
``````
``````# Python star pattern to print triangle

def pattern(n):
for i in range(n):
# print star
print(" " * (n-i-1) + "*" * (2*i+1))

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-6

``````Enter number of row: 3

* * * *
* * *
* *
*
``````
``````def pattern(n):
a = (2 * n) - 2
for i in range(n, -1, -1):
for j in range(a, 0, -1):
print(end=" ")

a = a + 1
for j in range(0, i+1):
print("* ",end="")
print("\r")

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-7

``````Enter number of row: 6

*
*   *
*   *   *
*   *   *   *
*   *   *   *   *
*   *   *   *   *   *
``````
``````def pattern(n):
a = n - 1
for i in range(n):
for j in range(a):
print(end=" ")

a = a - 1
for j in range(i+1):
print("* ",end="  ")
print("\r")

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-8

``````Enter number of row: 4

*
* *
* * *
* * * *
* * *
* *
*
``````
``````def pattern(n):
for i in range(n):
for j in range(n-i-1):
print(" ", end=" ")
for j in range(i+1):
print("* ",end="")
print()

for i in range(n-1):
for j in range(i+1):
print(" ",end=" ")
for j in range(n-i-1):
print("* ",end="")
print()

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-9

Enter number of row: 3
`** ** * ** **`

``````# Python star pattern to print right pascal triangle

def pattern(n):
for i in range(n):
print('* ' * (i + 1))
for i in range(n):
print('* ' * (n - i - 1))

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Star Triangle in Python using While Loop

Triangle Star Pattern-10

Enter number of row: 3
`** ** * *`

``````def pattern(n):
i = 1
while i<=n:
print("* " * i)
i+=1

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-11

Enter number of row: 3
`* * ** **`

``````# Python star pattern to print downward left half triangle

def pattern(n):
i = n
while i>=1:
# printin star
print("* " * i)
i-=1

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-12

``````Enter number of row: 4

*
**
***
****
``````
``````# Python star pattern to print right half triangle

def pattern(n):
i = 1
while i<=n:
print(" "*(n-i) + "*" * i)
i+=1

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-13

``````Enter number of row: 6

******
*****
****
***
**
*
``````
``````def pattern(n):
i = n
while i>=1:
print(" "*(n-i) + "*" * i)
i-=1

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-14

``````Enter number of row: 6

*
* *
* * *
* * * *
* * * * *
* * * * * *
``````
``````def pattern(n):
i = 1
while i<=n:
print(" "*(n-i) + "* " * i)
i+=1

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-15

``````Enter number of row: 5

* * * * *
* * * *
* * *
* *
*
``````
``````def pattern(n):
i = n
while i>=1:
# printin star
print(" "*(n-i) + "* " * i)
i-=1

# take inputs
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-16

Enter number of row: 4
`** ** * ** * * ** * ** **`

``````def pattern(n):
i = 1
while i<n:
print("* " * i)
i+=1

i = n
while i>=1:
print("* " * i)
i-=1

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-17

``````Enter number of row: 4

*
**
***
****
***
**
*
``````
``````def pattern(n):
i = 1
while i<n:
print(" "*(n-i) + "*" * i)
i+=1

i = n
while i>=1:
print(" "*(n-i) + "*" * i)
i-=1

# take inputs
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern in Python

In the below programs, we will print the hollow triangle star pattern.

Triangle Star Pattern-18

``````Enter number of row: 6

*
* *
*   *
*     *
*       *
* * * * * *
``````
``````def pattern(n):
for i in range(1, n+1):
for j in range(i):
if j == 0 or j == i-1:
print("*", end=" ")
else:
if i != n:
# printing spaces
print(" ", end=" ")
else:
# print star
print("*", end=" ")
print()

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-19

``````Enter number of row: 5

* * * * *
*     *
*   *
* *
*
``````
``````def pattern(n):
for i in range(n, 0, -1):
for j in range(i, 0, -1):
if i == 1 or i == n or j == 1 or j == i:
print("*", end=" ")
else:
# printing spaces
print(" ", end=" ")
print()

# take inputs
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-20

``````Enter number of row: 6

*
*   *
*       *
*           *
*               *
* * * * * * * * * * *
``````
``````def pattern(n):
for i in range(n):
for j in range(n-i-1):
print(" ", end=" ")

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

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Triangle Star Pattern-21

``````Enter number of row: 4

* * * * * * *
*       *
*   *
*
``````
``````def pattern(n):
for i in range(1, n+1):
for j in range(0, i):
# printing spaces
print(" ", end=" ")

for j in range(1, (n*2 - (2*i-1)) + 1):
if i == 1 or j == 1 or j ==(n*2 -(2*i-1)):
print("*", end=" ")
else:
print(" ", end=" ")
print()

# take input
n = int(input('Enter number of row: '))

# function call
pattern(n)
``````

Also See:- Pattern Programs in C