# Print * as a box

### muTheTechie twitter logo github logo Mar 18・1 min read

``````maxRows = 10
maxCols = 100
for i in range(maxRows):
star = "*"
for j in range(maxCols-2):
if(i==0 or i==maxRows-1):
star = star + "*"
else:
star = star + " "
print(star+"*")
`````` DISCUSS (3) What about

``````n, m
print("*" * n)
print(("*" + " " * (n-2) + "*\n") * m - 2)
print("*" * n)
``````

(sorry, I can't sleep)

it throws error... but fixed it and the latest is

``````n=10
m=5
print("*" * n)
print(("*" + " " * (n-2) + "*\n") * (m - 2))
print("*" * n)
`````` But how to avoid the unnecessary new line, @protium ?

Sorry, I didn't test it. You could add another print before the last line and multiply by `m - 3`. But notice that the code I wrote is awful and has a terrible performance. I just wanted to point out what awesome things you can do with python.

A good practice will be to solve it with just one for loop. It will have the same time complexity but it implies more math.

Classic DEV Post from Sep 27 '18

## My solution is the best!  