Python program to display half diamond pattern of numbers with star border
Given a number n, the task is to write a Python program to print a half-diamond pattern of numbers with a star border.
Input: n = 5 Output: * *1* *121* *12321* *1234321* *123454321* *1234321* *12321* *121* *1* * Input: n = 3 Output: * *1* *121* *12321* *121* *1* *
- Two for loops will be run in this program in order to print the numbers as well as stars.
- First print * and then run for loop from 1 to (n+1) to print up to the rows in ascending order.
- In this particular for loop * will be printed up to i and then one more for loop will run from 1 to i+1 in order to print the numbers in ascending order.
- Now one more loop will run from i-1 to 0 in order to print the number in the reverse order.
- Now one star will be printed and this for loop will end.
- Now second for loop will run from n-1 to 0 to print the pattern as in the middle in which the numbers are in a reverse manner.
- In this for loop also the same work will be done as in first for loop.
- The required pattern will be displayed.
Below is the implementation of the above pattern:
For n = 5 * *1* *121* *12321* *1234321* *123454321* *1234321* *12321* *121* *1* * For n = 3 * *1* *121* *12321* *121* *1* *
My Personal Notes arrow_drop_up
Please Login to comment...