Pattern Programs · Python example
Print a right-angled triangle of consecutive natural numbers.
Floyd's triangle fills a triangle with consecutive numbers. A nested loop handles the growing width of each row.
rows = 4
number = 1
for row in range(1, rows + 1):
values = []
for _ in range(row):
values.append(str(number))
number += 1
print(" ".join(values))