This Python program reads an integer n between 1 and 80 and prints a centered triangle using asterisks (*).
Each row contains one more asterisk than the previous, and the pattern is padded with spaces to align the triangle symmetrically.
# Read n from user
n = int(input("Enter a number between 1 and 80: "))
# Validate input
if 1 <= n <= 80:
for i in range(1, n + 1):
spaces = ' ' * (n - i)
stars = '* ' * i
print(spaces + stars.strip())
else:
print("The number must be between 1 and 80.")
*
* *
* * *
* * * *
* * * * *
- The user inputs a number n
- For each row i from 1 to n:
— The program prints n - i spaces to center the row
— Then it prints i asterisks separated by spaces
— The .strip() method removes trailing space for clean alignment