To print a number triangle in Python using a loop-based program, you can follow a simple approach. Here's an example code snippet that achieves the desired output:
rows = 6 # Number of rows in the triangle
for i in range(1, rows + 1): # Iterate over each row
for j in range(i): # Repeat the number i for each column in the row
print(i, end=" ") # Print the number followed by a space
print() # Move to the next line after printing the row
In this code, we use two nested for loops. The outer loop iterates over each row, starting from 1 and going up to the specified number of rows (rows). The inner loop repeats the number i for each column in the row, where i corresponds to the current row number. We use the print() function with end=" " to print the number followed by a space, and then call print() again without any arguments to move to the next line and start a new row.