Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34699

Re: Hollow square program

References <1aa414f0-1e4c-424b-abc6-8e681631788b@googlegroups.com>
Date 2012-12-13 03:59 +1100
Subject Re: Hollow square program
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.779.1355331602.29569.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Dec 13, 2012 at 3: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("")

You're going to need some kind of special handling of the beginning
and end of each row, except for the first and last rows. Since you
have i and j counting up from 0 to (rows-1), you can do this by simply
checking those two variables and then decide whether to print out a
star or a space (or, since there's spaces after the stars, whether to
print out a star and a space or two spaces).

Since you're being taught loops, I'm confident your course will have
already taught you how to make a decision in your code. It's another
Python statement.

Next time, by the way, you may want to explicitly state that this is
part of a course you're studying. Otherwise, you may come across as
sneakily trying to cheat your way through the course, which I'm sure
you would never do, would you? :) We're happy to provide hints to help
you understand Python, but not to simply give you the code (and if
anybody does, I hope you have the integrity, and desire to learn, to
ignore that post and work it out for yourself).

Have fun!

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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