Write a program to print Floyd’s triangle number pattern in python language( Ascending and Descending Orders).
There are you will learn how to print Floyd’s triangle number pattern by using the for loop.
Program to print Floyd’s triangle
Python program: Write a program to print Floyd’s triangle number pattern in python language
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# Write a program to print Floyd's triangle number pattern in python language r, i, j, n = None, None, None, 1 # x - denotes the number of rows print ("-----Kindly enter the number of rows to print Floyd's triangle number pattern-----:") r = int (input ()) print ("\n-----This is Floyd's triangle number pattern-----\n") for i in range (1, r + 1): print (end="\t") for j in range (1, i + 1): print (n, end="\t") n = n + 1 print (end="\n\n") |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
-----This is Floyd's triangle number pattern----- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
Program to print Reverse Floyd’s triangle
Python program: Write a program to enter the number and print the floyd’s triangle in decreasing order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# Write a program to print Floyd's triangle number pattern in python language r, i, j, n = None, None, None, 1 # x - denotes the number of rows print ("-----Kindly enter the number of rows to print Floyd's triangle number pattern-----") r = int (input ()) print ("\n-----This is Floyd's triangle number pattern-----\n") for i in range (r + 1, 1, -1): print (end="\t") for j in range (i, 1, -1): print (n, end="\t") n = n + 1 print (end="\n\n") |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
-----Kindly enter the number of rows to print Floyd's triangle number pattern----- 10 -----This is Floyd's triangle number pattern----- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |