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


Groups > comp.lang.python > #67339 > unrolled thread

Boxes of O's

Started bygeniusrko@gmail.com
First post2014-03-01 11:12 -0800
Last post2014-03-01 22:04 -0500
Articles 10 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  Boxes of O's geniusrko@gmail.com - 2014-03-01 11:12 -0800
    Re: Boxes of O's Chris Angelico <rosuav@gmail.com> - 2014-03-02 06:16 +1100
      Re: Boxes of O's geniusrko@gmail.com - 2014-03-01 11:28 -0800
        Re: Boxes of O's MRAB <python@mrabarnett.plus.com> - 2014-03-01 19:41 +0000
        Re: Boxes of O's Chris Angelico <rosuav@gmail.com> - 2014-03-02 06:54 +1100
          Re: Boxes of O's geniusrko@gmail.com - 2014-03-02 06:43 -0800
            Re: Boxes of O's Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 14:56 +0000
            Re: Boxes of O's Glazner <yoavglazner@gmail.com> - 2014-03-02 13:30 -0800
            Re: Boxes of O's Michael Torrie <torriem@gmail.com> - 2014-03-02 14:48 -0700
        Re: Boxes of O's Dave Angel <davea@davea.name> - 2014-03-01 22:04 -0500

#67339 — Boxes of O's

Fromgeniusrko@gmail.com
Date2014-03-01 11:12 -0800
SubjectBoxes of O's
Message-ID<c753ba44-379b-4322-96c0-4ba5cb8fa7c1@googlegroups.com>
Hi 
Can anyone help with this problem 

Create a big box out of n rows of little o's for any desired size n. Use an input statement to allow the user to enter the value for n and then print the properly sized box.

E.g. n = 3						
oooooo
o    o
oooooo

E.g. n = 8
oooooooooooooooo
o              o
o              o
o              o
o              o
o              o
o              o
oooooooooooooooo


using only loops
Thanks

[toc] | [next] | [standalone]


#67340

FromChris Angelico <rosuav@gmail.com>
Date2014-03-02 06:16 +1100
Message-ID<mailman.7529.1393701408.18130.python-list@python.org>
In reply to#67339
On Sun, Mar 2, 2014 at 6:12 AM,  <geniusrko@gmail.com> wrote:
> Create a big box out of n rows of little o's for any desired size n. Use an input statement to allow the user to enter the value for n and then print the properly sized box.

How far have you gotten so far with your homework? Show us some code
and we can help you debug it.

ChrisA

[toc] | [prev] | [next] | [standalone]


#67341

Fromgeniusrko@gmail.com
Date2014-03-01 11:28 -0800
Message-ID<31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com>
In reply to#67340
Well, This is what i got 

n = int(input("enter number of o: "))

for i in range(n):
    print("O", end = '')
    for j in range(n* 2):
        print("O", end = '')
    
    print()

[toc] | [prev] | [next] | [standalone]


#67342

FromMRAB <python@mrabarnett.plus.com>
Date2014-03-01 19:41 +0000
Message-ID<mailman.7530.1393703078.18130.python-list@python.org>
In reply to#67341
On 2014-03-01 19:28, geniusrko@gmail.com wrote:
> Well, This is what i got
>
> n = int(input("enter number of o: "))
>
> for i in range(n):
>      print("O", end = '')
>      for j in range(n* 2):
>          print("O", end = '')
>
>      print()
>
 From the examples:

   The first row has n*2 of 'o'
   There are n-2 middle rows, each with 'o', then n*2-2 spaces, then 'o'
   The last row has n*2 of 'o'

Incidentally, in your code you're writing 'O', not 'o'.

[toc] | [prev] | [next] | [standalone]


#67344

FromChris Angelico <rosuav@gmail.com>
Date2014-03-02 06:54 +1100
Message-ID<mailman.7532.1393703673.18130.python-list@python.org>
In reply to#67341
On Sun, Mar 2, 2014 at 6:28 AM,  <geniusrko@gmail.com> wrote:
> Well, This is what i got
>
> n = int(input("enter number of o: "))
>
> for i in range(n):
>     print("O", end = '')
>     for j in range(n* 2):
>         print("O", end = '')
>
>     print()

Okay! Good. Now, presumably this isn't working yet, or you wouldn't be
asking. So we just need the other crucial part of the puzzle: What is
it doing wrong? That might be an exception (copy and paste it all,
including the full traceback), or it might be producing the wrong
output, or maybe it produces the right output on everything except
some specific input.

I'll level with you here. We do not want to do your homework for you,
and we do not want anyone else to do your homework. When you're asked
to write code like this, it's not because the teacher/tutor wants the
code written - it's because you need to learn what you're doing.
Having someone else hand you perfectly working code defeats that
purpose, and it will tend to produce a sort of faux comprehension that
results in you getting a certificate and a job, while being still
quite incompetent as a programmer. Now, you may protest that it's not
as bad as that (and you'd probably be right - you have produced some
partially-working code there), but that's the extreme, and going even
part-way down that path is a Bad Thing. We, as programmers, would hate
to be coworkers to someone who glided through some course by getting
someone else to do the work; we do not want to have to try to work
with that sort of person.

(Digression: I have, and quite a few of us here probably have, worked
with exactly such a person. In my case, eventually even the boss/owner
figured out that he was a rubbish programmer; when we eventually dug
into his code thoroughly, we threw out the whole lot and literally
started over with a blank file. But before that, we found gems like
this PHP code - by the way, it *is* possible to write good PHP code,
even though the language is itself pretty appalling, but this... isn't
proof of that.

$step = 1;
do
{
    switch ($step) {
        case 1:
            .... code code code ....
            break;
        case 2:
            .... code code code ....
            break;
        default:
            ... raise an error ....
    }
} while (++$step<2);

This code was supposed to verify certain requirements on an incoming
HTTP request. What you may not notice - and I didn't notice when I saw
this and decided to simplify the code - is that this is NOT the
for-switch paradigm, it's something even worse: a for-switch with an
off-by-one, so the only code actually executed is the "case 1" block.
And since we had properly working code in our client, none of the
errors that the "case 2" block was supposed to catch ever actually got
triggered, so we didn't see a problem... until I cleaned up the code,
and discovered that "case 2" had bugs in it. This is what happens when
you have incompetent people writing code. This is why we are strongly
disinclined to give you the answers. End digression.)

However, while we won't just give you the answers, we *will* gladly
help you to understand what's going on. So if you post code and output
(maybe an error) and ask a specific question, preferably one that
shows some level of comprehension, we will cheerfully put in quite a
bit of time to help you understand the error message, or learn how to
decipher Python tracebacks, or whatever. Helping you to understand
things makes you a better programmer, and by extension improves the
world's total programming skill; giving you the answers makes you no
better and possibly worse (by encouraging laziness), and so we don't
want to do it.

So, there you have it. Don't be a bad programmer. :) You'll find more
handy tips here - it's an invaluable resource:

http://www.catb.org/~esr/faqs/smart-questions.html

ChrisA

[toc] | [prev] | [next] | [standalone]


#67446

Fromgeniusrko@gmail.com
Date2014-03-02 06:43 -0800
Message-ID<729104f4-92f8-48a3-9b7c-e7ba4fb6a38e@googlegroups.com>
In reply to#67344
I agree with you and really appreciate your experience. But what I was looking for is clues. Thank you anyway

[toc] | [prev] | [next] | [standalone]


#67447

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-02 14:56 +0000
Message-ID<mailman.7582.1393772231.18130.python-list@python.org>
In reply to#67446
On 02/03/2014 14:43, geniusrko@gmail.com wrote:
> I agree with you and really appreciate your experience. But what I was looking for is clues. Thank you anyway
>

Sorry, can't resist this one https://www.youtube.com/watch?v=oaGpaj2nHIo :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#67470

FromGlazner <yoavglazner@gmail.com>
Date2014-03-02 13:30 -0800
Message-ID<86560890-42bb-4090-a178-1669d4486dcf@googlegroups.com>
In reply to#67446
On Sunday, March 2, 2014 4:43:48 PM UTC+2, geni...@gmail.com wrote:
> I agree with you and really appreciate your experience. But what I was looking for is clues. Thank you anyway

#not tested
for i in range(n):
  for j in range(n*2):
    if i in (0, n - 1) or j in (0, n*2 - 1):
      print('o', end='')
    else:
      print(' ', end='')
   print()

[toc] | [prev] | [next] | [standalone]


#67472

FromMichael Torrie <torriem@gmail.com>
Date2014-03-02 14:48 -0700
Message-ID<mailman.7597.1393796889.18130.python-list@python.org>
In reply to#67446
On 03/02/2014 07:43 AM, geniusrko@gmail.com wrote:
> I agree with you and really appreciate your experience. But what I
> was looking for is clues. Thank you anyway

Not sure what you mean. Chris certainly offered you clues to solving
this problem.  Certainly he pointed you in the right direction to learn
how to approach a problem and debug code.  Seems like what you really
wanted was the answer to be given you for this homework problem.  And
usually someone is willing to step up and do the work for you, so you
lucked out.

[toc] | [prev] | [next] | [standalone]


#67406

FromDave Angel <davea@davea.name>
Date2014-03-01 22:04 -0500
Message-ID<mailman.7559.1393729214.18130.python-list@python.org>
In reply to#67341
 geniusrko@gmail.com Wrote in message:
> Well, This is what i got 
> 
> n = int(input("enter number of o: "))
> 
> for i in range(n):
>     print("O", end = '')
>     for j in range(n* 2):
>         print("O", end = '')
>     
>     print()
> 

Are you permitted to write and call functions? If so, then write
 functions to solve pieces of the problem, and call those
 functions from your main one.  That's called factoring,  and is
 an important tool.

In this case,  one function could print a row of 'o' of length
 siz, while the second one print a 'hollow' row. Then your main
 calls first, then loops calling hollow, then calls first
 again.

-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web