Basic Programs

If Else Programs

While loop Programs

For loop Programs

List Programs


Python Program to Print Star Pattern in M Shape


This example shows, how to print M shape star pattern.

Example.py
a = int(input("Enter the Rows: "))  
for i in range(a):
    for j in range(a):
        if j == 0 or j == a-1 or (i == j and j <= a//2) or (i + j == a-1 and j >= a//2):
            print("*", end="")
        else:
            print(" ", end="")
    print() 

Output

Enter the Rows: 15

*             *
**           **
* *         * *
*  *       *  *
*   *     *   *
*    *   *    *
*     * *     *
*      *      *
*             *
*             *
*             *
*             *
*             *

Prev Next