Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34700
| Date | 2012-12-12 12:18 -0500 |
|---|---|
| From | Mitya Sirenef <msirenef@lightbird.net> |
| Subject | Re: Hollow square program |
| References | <1aa414f0-1e4c-424b-abc6-8e681631788b@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.780.1355332724.29569.python-list@python.org> (permalink) |
On 12/12/2012 11:48 AM, siimnurges@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="")
> print("")
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
-m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Hollow square program siimnurges@gmail.com - 2012-12-12 08:48 -0800
Re: Hollow square program Chris Angelico <rosuav@gmail.com> - 2012-12-13 03:59 +1100
Re: Hollow square program siimnurges@gmail.com - 2012-12-12 09:22 -0800
Re: Hollow square program Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-12 10:35 -0700
Re: Hollow square program Peter Otten <__peter__@web.de> - 2012-12-12 18:44 +0100
Re: Hollow square program siimnurges@gmail.com - 2012-12-12 09:52 -0800
Re: Hollow square program Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-12-12 23:47 +0000
Re: Hollow square program Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-13 00:12 +0000
Re: Hollow square program siimnurges@gmail.com - 2012-12-12 09:52 -0800
Re: Hollow square program siimnurges@gmail.com - 2012-12-12 09:22 -0800
Re: Hollow square program Mitya Sirenef <msirenef@lightbird.net> - 2012-12-12 12:18 -0500
Re: Hollow square program siimnurges@gmail.com - 2012-12-12 09:25 -0800
Re: Hollow square program siimnurges@gmail.com - 2012-12-12 09:25 -0800
csiph-web