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


Groups > comp.lang.python > #42996

Re: Newbie to python. Very newbie question

Date 2013-04-07 07:50 -0400
From Dave Angel <davea@davea.name>
Subject Re: Newbie to python. Very newbie question
References <f0759987-4ff8-49a1-a826-4ae3f6508030@5g2000yqz.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.239.1365335449.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 04/07/2013 07:16 AM, ReviewBoard User wrote:
> Hi
> I am a newbie to python

Then why are you trying to do 7 or 8 things on one line?

> and am trying to write a program that does a
> sum of squares of numbers whose squares are odd.
> For example, for x from 1 to 100, it generates 165 as an output (sum
> of 1,9,25,49,81)
>

No it doesn't.  A small piece of it does, and I'd recommend making that 
piece a separate line or three, probably making a function out of it.

Then if you want to write other code to exercise that function, go right 
ahead.

If you're new to Python, concentrate on the algorithm needed, and keep 
the program straightforward.  After you've got something simple working, 
and you're comfortable with the algorithm, then you can play code-golf 
to your heart's content.

Perhaps you hadn't realized that any odd number when squared will yield 
an odd number, and likewise for even.  So the stated problem is much 
simpler than what you're trying to do.

3 lambda's in one line of code?  Silly.



-- 
DaveA

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


Thread

Newbie to python. Very newbie question ReviewBoard User <lalitha.viswanath@gmail.com> - 2013-04-07 04:16 -0700
  Re: Newbie to python. Very newbie question Kruno Saho <kruno.saho@gmail.com> - 2013-04-07 04:19 -0700
  Re: Newbie to python. Very newbie question Dave Angel <davea@davea.name> - 2013-04-07 07:50 -0400
  Re: Newbie to python. Very newbie question rusi <rustompmody@gmail.com> - 2013-04-07 10:02 -0700
  Re: Newbie to python. Very newbie question Miki Tebeka <miki.tebeka@gmail.com> - 2013-04-07 10:04 -0700
  Re: Newbie to python. Very newbie question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-07 15:09 -0400
    Re: Newbie to python. Very newbie question Miki Tebeka <miki.tebeka@gmail.com> - 2013-04-07 16:57 -0700
  Re: Newbie to python. Very newbie question Ian Foote <ian@feete.org> - 2013-04-07 20:23 +0100
  Re: Newbie to python. Very newbie question Arnaud Delobelle <arnodel@gmail.com> - 2013-04-07 21:16 +0100
  Re: Newbie to python. Very newbie question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-08 03:16 +0000

csiph-web