Floyd’s Triangle Pattern in Python

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.

Floyd's Triangle pattern - programminginpython.com
Floyd’s Triangle pattern – programminginpython.com

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.

Program on Github

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

Program on Github

Output

Floyd's Triangle pattern - programminginpython.com
Floyd’s Triangle pattern – programminginpython.com
Floyd's Triangle pattern - programminginpython.com
Floyd’s Triangle pattern – programminginpython.com

Floyd’s Triangle Pattern – Code Visualization

Program on Github

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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.