Hollow square program

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 12 18:35:19 CET 2012

On Wed, Dec 12, 2012 at 10:22 AM,  <siimnurges at gmail.com> wrote:
> Well, I did some modifications and got a hollow square, but the columns aren't perfectly aligned with the rows (at least if input is 5. Thanks for the help :)
> rows = int(input())
> s1="* "*rows
> s2="*"+(rows-2)*" "+"*"
> print(s1)
> for s in range(rows-2):
>     print(s2)
> print(s1)

The (rows-2)*" " in s2 is only enough spaces to account for the
(rows-2) inner * characters in s1.  You also need additional spaces in
s2 to match up with for the (rows-1) space characters in between the *
characters in s1.

More information about the Python-list mailing list