Print Floyd's Triangle in Python
Print Floyd's triangle (consecutive numbers in a right-angled triangle).
BeginnerLoop ProgramsExample 24 of 25
print-floyd-s-triangle.py
1# Program to print Floyd's triangle23rows = int(input("Enter number of rows: "))45num = 16for i in range(1, rows + 1):7 for j in range(i):8 print(num, end=" ")9 num += 110 print()
Output
Enter number of rows: 4 1 2 3 4 5 6 7 8 9 10
What's going on
We keep a running counter and print increasing numbers row by row.
After this program
If the idea is still fuzzy, read Day 9: Loops and Iteration in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 loop programs, or see every topic on Python exercises.