Print Floyd's Triangle

Print Floyd's triangle (consecutive numbers in a right-angled triangle).

BeginnerTopic: Loop Programs
Back

Python Print Floyd's Triangle Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# Program to print Floyd's triangle

rows = int(input("Enter number of rows: "))

num = 1
for i in range(1, rows + 1):
    for j in range(i):
        print(num, end=" ")
        num += 1
    print()
Output
Enter number of rows: 4
1 
2 3 
4 5 6 
7 8 9 10 

Understanding Print Floyd's Triangle

We keep a running counter and print increasing numbers row by row.

Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.

Table of Contents