











Python Program for Inverted Incrementing Diamond Pattern
Print Inverted Incrementing Diamond Pattern
In this Python Program, we will be discussing how to write a program to print the Inverted Incrementing Diamond Pattern. In this pattern, there are num*2-1 numbers of rows are present where ‘num’ is entered by the users. We will use the ‘k’ variable which is initially initialized by 3 for printing number increasing order. With every iteration of for loop, we will increase the k variable by i. Once the above increasing order triangle gets printed then move to the decreasing triangle pattern. In this pattern, With every iteration of for loop, we will decrease the k variable by i. So, Users have to enter a single value, that will be determined as a number of rows and columns of the pattern. With the help of “for loop”, we will print the Inverted Incrementing Diamond Pattern.


Working:
Step 1. Start
Step 2. Take number of rows as input from the user and stored it into num.
Step 3. Take a variable ‘k’ and initialize it as 3.
Step 4. Run a loop ‘i’ number of times to iterate through all the rows which is Starting from i=0 to num.
Step 5. Run a nested loop inside the main loop for printing spaces which is starting from j=0 to i+i.
Step 6. Print ‘k’ inside the nested loop for each row.
Step 7. Outside the Second for loop, Increase k variable by 1.
Step 8. Move to the next line by printing a new line using print() function.
Step 9. Decrease the value of ‘k’ variable by 2.
Step 10. Run a loop ‘i’ number of times to iterate through all the rows which is Starting from i=0 to num.
Step 11. Run a nested loop inside the main loop for printing spaces which is starting from j=0 to num-i-1.
Step 12. Print ‘k’ inside the nested loop for each row.
Step 13. Outside the Second for loop, Decrease ‘k’ variable by 1.
Step 14. Move to the next line by printing a new line using print() function.
Step 15. Stop
Python Program:
num = int(input("Enter the Number: ")) k = 3 for i in range(0, num): for j in range(0, i+1): print(k, end="") k = k + 1 print() k = k - 2 for i in range(0, num): for j in range(0, num-i-1): print(k, end="") k = k - 1 print() # This code is contributed by Shubhanshu Arya (Prepinsta Placement Cell Student)
Login/Signup to comment