python square star pattern



Ram Bhardwajverified

@Sidharth

Founder and CEO at SidTube. Instagram: https://sidtu.be/r/instagram Discord: https://sidtu.be/r/MyDiscordServer

Python Star sqaure pattern

Make a star square pattern with length of side of square = 3

# make a star pattern like 

*   *   *
*        *
*   *   *

# with n = 3

So here we go,

n = 3

lets take the side of square to be "n".

 

here's the main code

n = 3

star = " * "
default = "   "

for a in range(1, n+1):
    if a ==1 or a == n:
        print(star*n)
    else:
        print(star, default*(n-2), star)

output:-

 *  *  * 
 *       * 
 *  *  *

it doesn't look like square, rather it looks like a pentagon because of the font!

as space charactor in wider than a asterisk(*)

 


Related Articles