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.
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': break else: 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 print() print()
Here is the sample run of the above python program to illustrates how to print Floyd triangle:
You may also like to learn or practice the same program in other popular programming languages: