Hello everyone, welcome back to programminginpython.com! I am going to create a new series on pattern programming, I will start with Floyd’s Triangle pattern.

A Floyd’s Triangle is a right-angled triangle which is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner. It can also be filled with *’s or any characters as we want. Here I will show you two examples one with numbers and one with *’s.

**You can also watch the video on YouTube here.**

#### Task

Python Program to print a Floyd’s Triangle.

#### Approach

- Read an input integer for asking the range of the triangle using
`input()`

- Run 2 for loops, one for column looping and other for row looping, in the first loop, loop through the range of the triangle for column looping
- In the second loop, loop through the value of 1st loop + 1, this is for row looping
- Now print the index value for printing triangle with numbers and print * for printing triangle with *’s

#### Program

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 |
__author__ = 'Avinash' # Print a Floyd's Triangle # Range of the triangle size = int(input("Enter the range: \t ")) print("\nFLOYD'S TRIANGLE with numbers: \n") k = 1 # 2 for loops, one for column looping another for row looping # i loop for column looping and j loop for row looping for i in range(1, size + 1): for j in range(1, i + 1): print(k, end=" ") k = k + 1 print() print("\n") print("\nFLOYD'S TRIANGLE with *'s: \n") for i in range(1, size + 1): for j in range(1, i + 1): print('*', end=" ") print() print("\n") |

#### Output

#### Floyd’s Triangle Pattern – Code Visualization

Also feel free to go through the other posts related to GUI programming in python, or the common algorithms implemented in python or all of the posts here.

##### Course Suggestion

Machine Learning everywhere! So I strongly suggest you to take the course below.

Course: Machine Learning Adv: Support Vector Machines (SVM) Python

i want to print like this?

im not getting it?

1

3 2

6 5 4

10 9 8 7