Want to print a pattern of numbers? Here we have shared a python program to print a pattern of numbers with the example.
Copy the below python program and execute it to see the program output. At the end of this page we have also shared the program output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # Python program to print a pattern of numbers. n = 5 num = 1 gap = n - 1 for j in range(1, n + 1) : num = j for i in range(1, gap + 1) : print(" ", end="") gap = gap - 1 for i in range(1, j + 1) : print(num, end="") num = num + 1 num = num - 2 for i in range(1, j) : print(num, end="") num = num - 1 print() |
Program Output
1 2 3 4 5 | 1 232 34543 4567654 567898765 |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.