Python Program - Print Floyd's Triangle
Floyd's triangle is named after Robert Floyd and it is a right-angled triangular array of natural numbers. It is created by filling the rows of the triangle with consecutive natural numbers, starting with 1 at the top.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Example:
In the example below, a function called FloydTriangle is defined. It requires one parameter to pass as number of rows in the triangle and prints the given number of rows of Floyd's triangle.
# function for floyd triangle def FloydTriangle(n): value = 1 for i in range(1, n+1): for j in range(1, i+1): print(value, end=" ") value = value + 1 print() # test the code FloydTriangle(7)
The above code will give the following output:
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
Recommended Pages
- Python Program - To Check Prime Number
- Python Program - Bubble Sort
- Python Program - Selection Sort
- Python Program - Maximum Subarray Sum
- Python Program - Reverse digits of a given Integer
- Python - Swap two numbers
- Python Program - Fibonacci Sequence
- Python Program - Insertion Sort
- Python Program - Find Factorial of a Number
- Python Program - Find HCF of Two Numbers
- Python Program - Merge Sort
- Python Program - Shell Sort
- Stack in Python
- Queue in Python
- Python Program - Find LCM of Two Numbers
- Python Program - To Check Whether a Number is Palindrome or Not
- Python Program - To Check Whether a String is Palindrome or Not
- Python Program - Heap Sort
- Python Program - Quick Sort
- Python - Swap Two Numbers without using Temporary Variable