"""
Recommended Python Style Guide:
https://peps.python.org/pep-0008/#introduction
"""

"""
Solution 1: With nested loops
"""

while True:  # Infinite loop to keep asking for valid input
    n = input("Enter a number larger than 0: ")
    if not n.isdigit():  # If the input is not a digit, repeat the loop
        continue

    n = int(n)  # Convert input to an integer
    if n > 0:  # Proceed only if the number is greater than 0

        for i in range(n):  # Loop through rows for the triangle
            for j in range(n - i - 1):  # Print spaces, decreasing by row
                print(" ", end="")  # Print spaces in the current row
            for k in range(2 * i + 1):  # Print stars, increasing by odd numbers
                print("*", end="")  # Print stars in the current row
            print()  # Move to the next line after printing a row

        break  # Exit the infinite loop once a valid input is received

"""
Solution 2: Without nested loops, with string replication (*) and concatenation (+)
"""

while True:  # Infinite loop to keep asking for valid input
    n = input("Enter a number larger than 0: ")
    if not n.isdigit():  # If the input is not a digit, repeat the loop
        continue

    n = int(n)  # Convert input to an integer
    if n > 0:  # Proceed only if the number is greater than 0

        for i in range(n):  # Loop for the top rows
            spaces = " " * (n - i - 1)  # Calculate leading spaces
            stars = "*" * (2 * i + 1)  # Calculate number of stars
            print(spaces + stars)  # Print the row with spaces and stars

        break  # Exit the loop once a valid input is received
