Re: Newbie to python. Very newbie question

2013-04-07 Thread Steven D'Aprano
On Sun, 07 Apr 2013 04:16:27 -0700, ReviewBoard User wrote: > Hi > I am a newbie to python 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) > > Here is the code I

Re: Newbie to python. Very newbie question

2013-04-07 Thread Miki Tebeka
> I can't even read that mess... three nested lambda? I have to say this and other answers in this thread seem not that friendly to me. The OP said it's a newbie question, we should be more welcoming to newcomers. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie to python. Very newbie question

2013-04-07 Thread Arnaud Delobelle
On 7 April 2013 20:23, Ian Foote wrote: > I'm surprised no one has suggested: > import math sum( x*x for x in range(1, int(math.sqrt(100)), 2)) Yeah! And I'm surprised no one came up with: >>> from itertools import count, takewhile >>> sum(takewhile((100).__gt__, filter((2).__rmod__, m

Re: Newbie to python. Very newbie question

2013-04-07 Thread Ian Foote
On 07/04/13 20:09, Dennis Lee Bieber wrote: On Sun, 7 Apr 2013 04:16:27 -0700 (PDT), ReviewBoard User declaimed the following in gmane.comp.python.general: Hi I am a newbie to python and am trying to write a program that does a sum of squares of numbers whose squares are odd. For example, for

Re: Newbie to python. Very newbie question

2013-04-07 Thread rusi
On Apr 7, 4:16 pm, ReviewBoard User wrote: > Hi > I am a newbie to python 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) > > Here is the code I have > print re

Re: Newbie to python. Very newbie question

2013-04-07 Thread Miki Tebeka
> I am a newbie to python Welcome! I hope you'll do great things with Python. > and am trying to write a program that does a > sum of squares of numbers whose squares are odd. OK. > For example, for x from 1 to 100, it generates 165 as an output (sum > of 1,9,25,49,81) I don't follow, you seem to

Re: Newbie to python. Very newbie question

2013-04-07 Thread Dave Angel
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 (su

Re: Newbie to python. Very newbie question

2013-04-07 Thread Kruno Saho
On Sunday, April 7, 2013 9:16:27 PM UTC+10, ReviewBoard User wrote: > Hi > > I am a newbie to python 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) >

Newbie to python. Very newbie question

2013-04-07 Thread ReviewBoard User
Hi I am a newbie to python 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) Here is the code I have print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x:

RE: very newbie question

2008-08-07 Thread Peter Anderson
Try this: # The player tries to guess it and the computer lets # the player know if the guess is too high, too low # or right on the money import random print "\tWelcome to 'Guess My Number'!" print "\nI'm thinking of a number between 1 and 100." print "Try to guess it in as few attempts as pos

RE: very newbie question

2008-08-07 Thread Edwin . Madari
L PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of garywood Sent: Thursday, August 07, 2008 1:56 PM To: python-list@python.org Subject: very newbie question stuck on python for absolute beginners chapter 6 i actually done what i was supposed to do use the function ask_number for guess a number bu

Re: very newbie question

2008-08-07 Thread Ethan Furman
garywood wrote: stuck on python for absolute beginners chapter 6 i actually done what i was supposed to do use the function ask_number for guess a number but for some reason it does not count correctly the number of tries # Guess My Number # # The computer picks a random number between 1 and

very newbie question

2008-08-07 Thread garywood
stuck on python for absolute beginners chapter 6 i actually done what i was supposed to do use the function ask_number for guess a number but for some reason it does not count correctly the number of tries # Guess My Number # # The computer picks a random number between 1 and 100 # The player

Re: Confused yet again: Very Newbie Question

2008-07-08 Thread Lie
On Jul 7, 7:09 pm, Jeff <[EMAIL PROTECTED]> wrote: > When you call c3.createJoe(c1.fred), you are passing a copy of the > value stored in c1.fred to your function.  Python passes function > parameters by value. No, python doesn't pass variable either by value or by reference. The behavior in pytho

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread Terry Reedy
Jeff wrote: When you call c3.createJoe(c1.fred), you are passing a copy of the value stored in c1.fred to your function. Python passes function parameters by value. These statements are both wrong. Function argument objects or objects derived therefrom are bound to function parameter names

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread mcl
On Jul 7, 5:07 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Mon, 7 Jul 2008 05:41:22 -0700 (PDT), mcl <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > My use of classes is because I want two classes one for  global > > variables and one for global functions. > >    

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread Matt Nordhoff
Jerry Hill wrote: > On Mon, Jul 7, 2008 at 7:30 AM, mcl <[EMAIL PROTECTED]> wrote: >> I did not think you had to make the distinction between 'byvar' and >> 'byref' as in Basic. > > Python does not use "call by value" or "call by reference" semantics. > Instead, python's model is "call by object".

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread Peter Pearson
On Mon, 7 Jul 2008 05:41:22 -0700 (PDT), mcl <[EMAIL PROTECTED]> wrote: [snip] > My use of classes is because I want two classes one for global > variables and one for global functions. One of the many lovely things about programming in the Python style is that very few things need to be global.

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread Jerry Hill
On Mon, Jul 7, 2008 at 7:30 AM, mcl <[EMAIL PROTECTED]> wrote: > I did not think you had to make the distinction between 'byvar' and > 'byref' as in Basic. Python does not use "call by value" or "call by reference" semantics. Instead, python's model is "call by object". See this writeup for some

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread Matt Nordhoff
mcl wrote: > On 7 Jul, 13:09, Jeff <[EMAIL PROTECTED]> wrote: >> When you call c3.createJoe(c1.fred), you are passing a copy of the >> value stored in c1.fred to your function. Python passes function >> parameters by value. The function will not destructively modify its >> arguments; you must exp

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread mcl
On 7 Jul, 13:09, Jeff <[EMAIL PROTECTED]> wrote: > When you call c3.createJoe(c1.fred), you are passing a copy of the > value stored in c1.fred to your function.  Python passes function > parameters by value.  The function will not destructively modify its > arguments; you must expliticly state you

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread Jeff
When you call c3.createJoe(c1.fred), you are passing a copy of the value stored in c1.fred to your function. Python passes function parameters by value. The function will not destructively modify its arguments; you must expliticly state your intention to modify an object: class one(): fred =

Re: Confused yet again: Very Newbie Question

2008-07-07 Thread Matt Nordhoff
mcl wrote: > Why can I not the change the value of a variable in another class, > when I have passed it via a parameter list. > > I am sure I am being stupid, but I thought passed objects were Read/ > Write In Python, there are names which are bound to objects. Doing "foo = bar" and then "foo = s

Confused yet again: Very Newbie Question

2008-07-07 Thread mcl
Why can I not the change the value of a variable in another class, when I have passed it via a parameter list. I am sure I am being stupid, but I thought passed objects were Read/ Write eg #!/usr/bin/python class one(): #my Global Var

Re: very newbie question about exception handling

2007-12-26 Thread James Matthews
In short input runs an eval on the text before it passes it! So input like ord('a') will work fine because it will run that code! On Dec 26, 2007 5:26 AM, <[EMAIL PROTECTED]> wrote: > Thanks guys! It worked. > > Merry Christmas! > -- > http://mail.python.org/mailman/listinfo/python-list > --

Re: very newbie question about exception handling

2007-12-25 Thread Louis . Soninhu
Thanks guys! It worked. Merry Christmas! -- http://mail.python.org/mailman/listinfo/python-list

Re: very newbie question about exception handling

2007-12-24 Thread Ricardo Aráoz
[EMAIL PROTECTED] wrote: > code sample: > -- > i=input() > try: > x=int(i) > print "you input an integer" > except ValueError: > print "you must input an integer" > > when I input a value like,

very newbie question about exception handling

2007-12-24 Thread Louis . Soninhu
code sample: -- i=input() try: x=int(i) print "you input an integer" except ValueError: print "you must input an integer" when I input a value like, b I got the traceback message instead of prop