Python Program To Generate Pattern 2

Python Program To Generate Pattern 2

Write Python Program To Generate Pattern 2

# Write Python Program To Generate Pattern 2

n = 3
i = 1
while(i <= n):
    j = 1
    while(j <= n):
        if(i == 1 or i == n or j == 1 or j == n ):
            print('*', end = ' ')
        else:
            print(' ', end=' ')
        j = j + 1
    print('')
    i = i + 1

Output:

* * * 
*   * 
* * *