Hollow square program

Peter Otten __peter__ at web.de
Wed Dec 12 12:44:21 EST 2012


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 first and last row have an extra space between the asterisks. For the 
square to look like a square you need to add these to the other rows (and 
thus s2), too.

Also note that your code prints a minimum of two rows.




More information about the Python-list mailing list