Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Examples
  3. Floyd's Triangle

Pattern Programs · Python example

Floyd's Triangle

Print a right-angled triangle of consecutive natural numbers.

Open the compilerAll examples
beginnerpatternsnested loopsnumbers

Floyd's triangle fills a triangle with consecutive numbers. A nested loop handles the growing width of each row.

example.py
rows = 4
number = 1

for row in range(1, rows + 1):
    values = []
    for _ in range(row):
        values.append(str(number))
        number += 1
    print(" ".join(values))

How the code works

  • Row 1 contains 1.
  • Row 2 contains 2 and 3.
  • The counter continues from the previous row until 10 is printed.

Key ideas

  • The outer loop controls the number of rows.
  • The inner loop adds one number per column.
  • join() combines the row values with spaces.

Try changing it

  • Start from a number supplied by the user.
  • Print a triangle of even numbers only.
  • Use a while loop for the counter instead of a for loop.

Related examples

beginner

Star Pyramid Pattern

Use spaces and string repetition to print a centred star pyramid.

beginner

Multiplication Table

Print a ten-row multiplication table with a for loop and range().

Previous exampleStar Pyramid PatternNext exampleCelsius to Fahrenheit

Expected output

1
2 3
4 5 6
7 8 9 10

Output is compared after trimming trailing whitespace on each line. Run the code to see it produced by CPython in your browser.

Practice next

Apply the same idea with automatic tests or browse a guided project.

ExercisesProjects