This Python program reads an integer n between 0 and 80 and prints a two-part triangle pattern using asterisks (*).
The pattern consists of:
- An increasing triangle: rows from 1 to n
- A decreasing triangle: rows from n - 1 down to 1
If n = 0 is entered, the program defaults to n = 9 and prints a sample mirrored triangle.
# Read n from user
n = int(input("Enter a number between 0 and 80: "))
# Special case: n = 0 → show sample triangle
if n == 0:
n = 9 # default sample size
# Validate and print pattern
if 1 <= n <= 80 or n == 9:
# Increasing triangle
for i in range(1, n + 1):
print('* ' * i)
# Decreasing triangle
for i in range(n - 1, 0, -1):
print('* ' * i)
else:
print("The number must be between 0 and 80.")
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
- The user inputs a number n
- If n = 0, the program uses n = 9 as a default
- The first loop prints rows with increasing number of stars
- The second loop prints rows with decreasing number of stars
- The result is a mirrored triangle pattern with a peak in the middle