# Floyd’s Triangle in Python

Floyd’s Triangle in Python | Floyd’s Triangle is a right-angled triangular array that is made up of natural numbers. It is named after Robert Floyd. It starts from 1 and successively sets the subsequent greater number of the sequence. The total numbers in the triangle of n rows are n*(n+1)/2.

Here we will discuss, how to write a program in python programming to print a Floyd’s Triangle.

## Program to Print Floyd’s Triangle in Python Language

We can use nested for loop and while loop to print Floyd’s Triangle. Here we will make two programs, one using for loop and the other using the while loop.

Program to Print Floyd’s Triangle using For loop in Python Programming

We will make a program using “for loop”. So, firstly we will take input from the user to enter the number of rows to be present in Floyd’s Triangle. Then, we will implement a ‘nested for loop’ to make the pattern of Floyd’s triangle in Python Programming.

``````# Python Program to Print Floyd's Triangle
r = int(input("Enter the number of rows: "))
num = 1
print("Floyd's Triangle: ")
for i in range(1, r + 1):
for j in range(1, i + 1):
print(num, end='  ')
num = num + 1
print()``````

Output:-

Enter the number of rows: 5
Floyd’s Triangle:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

### Program to Print Floyd’s Triangle using While loop in Python Language

We will make the program using the “while loop” here. So, firstly we will take input from the user to enter the number of rows to be present in Floyd’s Triangle. Then, we will implement a ‘while loop’ to make the pattern of Floyd’s triangle in Python Language.

``````# Python Program to Print Floyd's Triangle
r = int(input("Enter the number of rows: "))
num = 1
print("Floyd's Triangle: ")
for i in range(1, r + 1):
for j in range(1, i + 1):
print(num, end='  ')
num = num + 1
print()``````

Output:-

Enter the number of rows: 5
Floyd’s Triangle:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Enter the number of rows: 7
Floyd’s Triangle:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28

Enter the number of rows: 9
Floyd’s Triangle:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45

So, here we discussed the Python Program to print Floyd’s Triangle using For loop and While loop. Hope you all find it useful.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!