Python Program to Print (Generate) Floyd's Triangle

This program prints Floyd's triangle up to n lines in Python language. Number of lines in Floyd's triangle is read from user.

Floyd's triangle is a right-angled triangular pattern of natural numbers. Floyd's triangle has 1 in first line, 2 & 3 in second line; 4, 5 & 6 in third line and so on.

Python Source Code: Floyd's Triangle

Python program for Floyd's triangle:


# Floyd's Triangle in Python

# Reading number of row
row = int(input('Enter number of rows: '))

# Setting number to 1
number = 1

print("Floyd's triangle is:")
for i in range(1,row+1):
    for j in range(1, i+1):
        print(number, end='\t')
        number += 1
    print()

Program Output

Enter number of rows: 6
Floyd's triangle is:
1	
2	3	
4	5	6	
7	8	9	10	
11	12	13	14	15	
16	17	18	19	20	21