Newbie to python. Very newbie question

Dave Angel davea at davea.name
Sun Apr 7 07:50:29 EDT 2013


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



More information about the Python-list mailing list