Python Program to Print Floyd Triangle

« Previous Program Next Program »

Print Floyd Triangle in Python

To print Floyd triangle in python, you have to ask from user to enter the number of rows or line upto which he/she want to print the desired Floyd triangle as shown in the program given below.

Python Programming Code to Print Floyd Triangle

Following python program ask from user to enter total number of line to print Floyd triangle expanded upto the given number of line or rows:

# Python Program - Print Floyd Triangle
while True:
	print("Enter 'x' for exit.")
	ran = input("Upto how many line ? ")
	if ran == 'x':
		rang = int(ran)
		k = 1
		for i in range(1, rang+1):
			for j in range(1, i+1):
				print(k, end=" ")
				k = k + 1

Here is the sample run of the above python program to illustrates how to print Floyd triangle:

python print floyd triangle

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test