GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Pattern Programming
  • AVINASH NETHALA
  • 4 years ago4 years ago
  • Previous: Pyramid Pattern in Python

This view

  • Original page
  • New address

GeezerVison is showing www.programminginpython.com — Floyds Triangle Pattern in Python - Programming 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

A Floyd’s Triangle is a right-angled triangle that 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 the 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 the triangle with numbers and print * for printing the triangle with *’s

Ad:
The Complete Python Bootcamp From Zero to Hero in Python – Enroll Now.
Udemy

Program

__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")

 

Program on GitHub

Output

Floyd’s Triangle Pattern

Floyd’s Triangle Pattern – Code Visualization

Program on GitHub

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

Course Suggestion

Machine Learning is everywhere! So I strongly suggest you to take the course below.
Course: Machine Learning Adv: Support Vector Machines (SVM) Python

 

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • More
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on WhatsApp (Opens in new window) WhatsApp

Online Python Compiler

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • More
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on WhatsApp (Opens in new window) WhatsApp

2 thoughts on “Floyds Triangle Pattern in Python”

  1. Great explanation of Floyd’s Triangle! The step-by-step code breakdown makes it easy to understand the pattern generation in Python. Can’t wait to try it out myself!

    Reply
  2. This is a fantastic explanation of Floyd’s Triangle! The examples you’ve provided in Python are clear and easy to follow. I can’t wait to try implementing this in my own projects. Thanks for sharing such valuable content!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Python program to print Fibonacci sequence

Python program to print Fibonacci sequence

AVINASH NETHALA4 years ago4 years ago 0
Python Program to print pattern of letter F

Python Program to print pattern of letter F

AVINASH NETHALA4 years ago3 years ago 0
Python Program to print pattern of Letter E

Python Program to print pattern of Letter E

AVINASH NETHALA4 years ago3 years ago 0
Reverse Pyramid Pattern in Python

Reverse Pyramid Pattern in Python

AVINASH NETHALA4 years ago4 years ago 0

Recent Posts

  • Python vs R: Which Language is Better for Data Science?
  • Top 7 Python Books You Must Read in 2025
  • Best Python Web Frameworks: Django, Flask, and FastAPI Breakdown
  • 20 Best Python One-Liners to Boost Your Coding Skills
  • Matplotlib Data Visualization in Python

Suggested Courses

  • Complete Python Developer: Zero to Mastery.
  • Automate the boring stuff.
  • Python and Django Full Stack Web Developer Bootcamp.
  • Artificial Intelligence and Machine Learning E-Degree.
  • Complete Python & Python OOP.

Subscribe to our newsletter!

Great Deals

Ads
  • Health and Beauty
  • Deals on Electronics
  • Toys and Games
  • Sports and Outdoors
  • Pet Supplies
  • Shoes
  • Movies and TV

Categories

  • Algorithms (8)
  • Artificial Intelligence AI (3)
  • Basic Programs (25)
  • Books (1)
  • Data Structures (10)
  • Databases (1)
  • Dictionaries (1)
  • Files Handling (1)
  • Letter Patterns (26)
  • Lists (7)
  • Machine Learning (3)
  • Math Programs (6)
  • Pattern Programming (31)
  • Promoted (1)
  • Python for Automation (1)
  • Python for Data Science (6)
  • Python for Ethical Hacking (2)
  • Python For Finance (4)
  • Python GUI (5)
  • Python Libraries (6)
  • Python OOP (1)
  • Python Resources (3)
  • Python Tips and Tricks (10)
  • Searching Algorithms (2)
  • Sets (1)
  • Sorting Algorithms (6)
  • Tuples (1)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.