Hollow square program
msirenef at lightbird.net
Wed Dec 12 18:18:29 CET 2012
On 12/12/2012 11:48 AM, siimnurges at gmail.com wrote:
> Hey, I need to write a program that prints out a square, which is empty on the inside. So far, I've
made a program that outputs a square, which is full on the inside.
> P.S. Between every asterisk there needs to be a space(" ")
> Here's my code:
> print("Rows: ")
> rows = int(input())
> for i in range(rows):
> for j in range(rows):
> print("* ", end="")
Small note: print("") is the same as print()
The general idea is: make a string that represents top/bottom of the
square, make a string for the middle part, print out the first string,
then print out middle part n-2 times, then print out first string again.
Did you know you can multiply strings? e.g.:
space = ' '
border = '*'
line = border + space*70
Lark's Tongue Guide to Python: http://lightbird.net/larks/
More information about the Python-list