Python Program for Printing Inverted Half Diamond Star Pattern

Print Inverted Half Diamond Star Pattern

In this Python Program, we will be discussing about how to write a program to print Inverted Half Diamond Star Pattern. In this pattern, there are n rows with i numbers of time of iterations through all the rows. In columns, num-i-1 numbers for printing Spaces and i+1 numbers for printing stars. Run another loop with i(Starts from 1) numbers of time of iterations through all the rows. In columns, i numbers for printing Spaces and num-i-1 numbers for printing stars. So, User have to enter a single value, that will be determine as a number of rows of the pattern. With the help of “Two Different Different Nested For Loop” , we will print the Inverted Half Diamond Star Pattern.

Python Program for Printing Inverted Half Diamond Star Pattern

Working:

Step 1. Start

Step 2. Take number of rows as input from the user and stored it into num.

Step 3. Run a loop ‘i’ number of times to iterate through all the rows which is Starting from i=0 to num. 

Step 4. Run a nested loop inside the main loop for printing spaces which is starting from j=0 to num-i-1.

Step 5. Run a nested loop inside the main loop for printing stars which is starting from j=0 to i+1.

Step 6. Move to the next line by printing a new line using print() function.

Step 7. Run a loop ‘i’ number of times to iterate through all the rows which is Starting from i=1 to num. 

Step 8. Run a nested loop inside the main loop for printing spaces which is starting from j=0 to i.

Step 9. Run a nested loop inside the main loop for printing stars which is starting from j=0 to num-i-1.

Stop 10. Move to the next line by printing a new line using print() function.

Step 11. Stop

Python Program:

num = int(input("Enter the Number: "))

for i in range(0, num):
    for j in range(0, num-i-1):
        print(" ", end="")
    for j in range(0, i+1):
        print("*",end="")
    print()

for i in range(1, num):
    for i in range(0, i):
        print(" ", end="")
    for j in range(0, num-i-1):
        print("*",end="")
    print()

# This code is contributed by Shubhanshu Arya (Prepinsta Placement Cell Student) 

9 comments on “Python Program for Printing Inverted Half Diamond Star Pattern”


  • anudeepthikolagani.999

    n=int(input(“Enter a number: “))
    for i in range(1,n+1):
    print((n-i)*’ ‘+’*’*i)
    for i in range(n-1,0,-1):
    print((n-i)*’ ‘+’*’*i)


  • NISHA V S

    n=int(input())
    m=0
    for i in range(n*2-1):
    if(i<((n*2-1)//2)):
    print(" "*(n-i-1)+"*"*(i+1))
    else:
    print(" "*m+"*"*((n*2-1)-i))
    m+=1


  • THIRUMALAIRAAJ

    rows = int(input(“Enter row value: “))
    for i in range(1,2*rows):
    if i <= rows:
    print(" "*(rows-i)+"*"*i)
    else:
    print(" "*(abs(rows-i))+"*"*(2*rows-i))


  • THIRUMALAIRAAJ

    //half diamond – inverted

    #include
    #include

    void main()
    {
    int rows,j = 1;
    printf(“Enter row value: “);
    scanf(“%d”,&rows);

    for(int i = 1; i < 2*rows; i++)
    {
    while(j <= rows)
    {
    if(j <= abs(rows-i))
    printf(" ");
    else
    printf("*");
    j++;
    }
    j = 1;
    printf("\n");


  • Ganta Rupesh

    n=int(input())
    for i in range(1,n+1):
    print(” “*(n-i)+”*”*i)
    if i==n:
    for i in range(1,n):
    print(” “*i+”*”*(n-i))


  • Abirbhab Boral

    For Java

    import java.util.*;
    public class InvertDiam{
    public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    System.out.println(“Enter a number”);
    int num = sc.nextInt();
    for (int i = 0;i <= num;i++){
    for (int j = 0; j<= num-i-1;j++)
    System.out.print(" ");
    for (int j = 0; j< i+1;j++)
    System.out.print("*");
    System.out.println();
    }
    for (int i =1; i<=num;i++){
    for (int j = 0; j< i;j++)
    System.out.print(" ");
    for (int j = 0; j<= num-i;j++)
    System.out.print("*");
    System.out.println();
    }
    }
    }


  • Debayudh

    import java.util.Scanner;
    public class PrintPattern {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.print(“Enter the Number: “);
    int num = scanner.nextInt();
    for (int i = 0; i < num; i++) {
    for (int j = 0; j < num – i – 1; j++) {
    System.out.print(" ");
    }
    for (int j = 0; j < i + 1; j++) {
    System.out.print("*");
    }
    System.out.println();
    }
    for (int i = 1; i < num; i++) {
    for (int j = 0; j < i; j++) {
    System.out.print(" ");
    }
    for (int j = 0; j < num – i; j++) {
    System.out.print("*");
    }
    System.out.println();
    }
    }
    }


  • Raghvendra Singh Shekhawat

    rows = int(input(“Enter the number of rows: “))

    for i in range(rows-1):
    for j in range(i,rows):
    print(” “, end=” “)
    for j in range(i+1):
    print(“*”, end=” “)
    print()
    for i in range(rows):
    for j in range(i+1):
    print(” “, end=” “)
    for j in range(i,rows):
    print(“*”, end=” “)
    print()


  • Shantanu

    // Java Code

    public static void main(String[] args)
    {
    Scanner scanner = new Scanner(System.in);
    System.out.print(“Enter the odd number of rows : “);
    int row = scanner.nextInt();
    for(int i = 1;ii;j–)
    System.out.print(” “);

    for(int j = 1;j=1;i–)
    {
    for(int j = (int)((row/2) + 0.5) + 1;j>i;j–)
    System.out.print(” “);

    for(int j = 1;j<=i;j++)
    System.out.print("*");

    System.out.println();
    }
    scanner.close();
    }