Re: easy question, how to double a variable

2009-12-28 Thread Tom Kermode
def twice(parameter = 2)
   return 4

2009/9/20 daggerdvm dagger...@yahoo.com:
  Write the definition of a function  twice , that receives an  int
 parameter and returns an  int that is twice the value of the
 parameter.

 how can i do this
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
http://www.kiloday.com
http://www.fourstopspast.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-10-02 Thread Albert van der Horst
In article fa454992-d61a-4fb7-b684-c8535bce5...@e18g2000vbe.googlegroups.com,
daggerdvm  dagger...@yahoo.com wrote:
you brain needs error checking!

Whose brain? At least I know this:

Your brain is beyond repair. Go for a brain transplant.

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-10-02 Thread Chris Colbert
I come from a scientific background, so my approach to the solution of
this problem is a little different.

It makes use of some numerical approximations, but that's not
necessarily a bad thing, because it helps avoid singularities. So it
could be a little more robust than other solutions presented here.

It also has a little more functionality: Say you wanted to return
three times a variable, you wouldnt want to write another function to
do that for you, so now you just pass in how many times you want the
variable repeated as the first parameter.

Hope this helps! Cheers!

import math

def repeat(how_many_times, x):
def f(n):
return 1./(2**n)

def summation(func, howmany):
if howmany == 1:
return func(1)
else:
return func(howmany) + summation(func, howmany-1)

def eulerify(num):
return abs(math.cos(math.pi) + 1j*(math.sin(math.pi))) * num

def get_coefficient(multiplier):
return eulerify(multiplier * summation(f, 100))

return int(eulerify(get_coefficient(how_many_times) * x))



On Fri, Oct 2, 2009 at 2:08 PM, Albert van der Horst
alb...@spenarnc.xs4all.nl wrote:
 In article 
 fa454992-d61a-4fb7-b684-c8535bce5...@e18g2000vbe.googlegroups.com,
 daggerdvm  dagger...@yahoo.com wrote:
you brain needs error checking!

 Whose brain? At least I know this:

 Your brain is beyond repair. Go for a brain transplant.

 Groetjes Albert

 --
 --
 Albert van der Horst, UTRECHT,THE NETHERLANDS
 Economic growth -- being exponential -- ultimately falters.
 alb...@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst

 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-24 Thread Iain King
On Sep 23, 7:36 pm, David C Ullrich dullr...@sprynet.com wrote:
 On Tue, 22 Sep 2009 02:34:53 +, Steven D'Aprano wrote:
  On Mon, 21 Sep 2009 13:50:23 -0500, David C Ullrich wrote:

  But you actually want to return twice the value. I don't see how to do
  that.

  What?

  Seriously?

 You're saying it _can_ be done in Python? They must have added
 something to the standard library again. I mean how can you return
 twice a value without a twice function to start with? I've tried.
 You'd think

 def twice(n):
   return twice(n)

 would work, but I get this really long error message.

  You're not just yanking the OP's chain???

 That would be cruel. I mean the guy has enough problems already...

Sorry, there is no 'twice' builtin.  I think what you are looking for
is:

def twice(n):
return return n


Iain
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-24 Thread Pablo Torres N.
On Sep 24, 5:51 am, Iain King iaink...@gmail.com wrote:
 On Sep 23, 7:36 pm, David C Ullrich dullr...@sprynet.com wrote:



  On Tue, 22 Sep 2009 02:34:53 +, Steven D'Aprano wrote:
   On Mon, 21 Sep 2009 13:50:23 -0500, David C Ullrich wrote:

   But you actually want to return twice the value. I don't see how to do
   that.

   What?

   Seriously?

  You're saying it _can_ be done in Python? They must have added
  something to the standard library again. I mean how can you return
  twice a value without a twice function to start with? I've tried.
  You'd think

  def twice(n):
    return twice(n)

  would work, but I get this really long error message.

   You're not just yanking the OP's chain???

  That would be cruel. I mean the guy has enough problems already...

 Sorry, there is no 'twice' builtin.  I think what you are looking for
 is:

 def twice(n):
     return return n

 Iain

Actually, what he wants is:

(def twice (x)
  (+ (once x) (once x)))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-24 Thread devilkin
On 9月22日, 上午4时49分, daggerdvm dagger...@yahoo.com wrote:
 you brain needs error checking!

this kid knows error checking...may be he know exceptions as well
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-23 Thread Rhodri James

On Mon, 21 Sep 2009 21:49:50 +0100, daggerdvm dagger...@yahoo.com wrote:


you brain needs error checking!


Your post, by contrast, needs grammar checking.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-23 Thread Steven D'Aprano
On Tue, 22 Sep 2009 07:41:11 -0700, Hyuga wrote:

  Forget ethical.  We can do his homework for him, we can perhaps pass
  exams for him, maybe graduate for him, and then with our luck, he'll
  get a job in our office and we get to do his work for him.

 No, no, no.  The plan is to do his homework for him so that he's
 incompetent when he graduates and won't be competition for the rest of
 us who did do our homework.
 
 Well, while they may not be as much competition come promotion time, I
 think Mr. Finney had it right that these people *do* still somehow get
 hired
...


It was Mel Wilson, not Ben Finney, who write the paragraph starting with 
Forget ethical.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-23 Thread Casey Webster
On Sep 22, 9:57 am, Grant Edwards inva...@invalid.invalid wrote:

 No, no, no.  The plan is to do his homework for him so that
 he's incompetent when he graduates and won't be competition for
 the rest of us who did do our homework.

Don't forget the Peter principal --- we might end up working for him!

Btw, I can't believe nobody provided the simplest literal solution:

def twice(i):
   return i, i
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-23 Thread Brian Blais

On Sep 23, 2009, at 8:15 , Casey Webster wrote:


Btw, I can't believe nobody provided the simplest literal solution:

def twice(i):
   return i, i
--


or this one, which is possibly even more literal:

def twice(p):

   return an int that is twice the value of the parameter


twice(an int parameter)

--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-23 Thread David C Ullrich
On Tue, 22 Sep 2009 02:34:53 +, Steven D'Aprano wrote:

 On Mon, 21 Sep 2009 13:50:23 -0500, David C Ullrich wrote:
 
 But you actually want to return twice the value. I don't see how to do
 that.
 
 What?
 
 Seriously? 

You're saying it _can_ be done in Python? They must have added
something to the standard library again. I mean how can you return
twice a value without a twice function to start with? I've tried.
You'd think

def twice(n):
  return twice(n)

would work, but I get this really long error message.

 You're not just yanking the OP's chain???

That would be cruel. I mean the guy has enough problems already...




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Processor-Dev1l
On Sep 20, 10:27 pm, daggerdvm dagger...@yahoo.com wrote:
  Write the definition of a function  twice , that receives an  int
 parameter and returns an  int that is twice the value of the
 parameter.

 how can i do this

I will stop this theatre...
as you should know, you want your function to make arithmetic
operation n*2.
Everything you have to do is to define some function with parameter n
and make this function to return n*2.
If you are not jerk, you can make the whole code you need from the
previous sentence :)))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Hendrik van Rooyen
On Monday, 21 September 2009 22:50:31 daggerdvm wrote:

 carl banks.you are a dork

No mister_do_my_homework, he is not.  
He is actually a respected member
of this little community.

You, however, are beginning to look like one.

Why do you not come clean - tell us what you are doing,
show us what you have tried, and maybe, just maybe, 
some kind soul will help you, instead of mocking you.

Although that is now less likely as you have started calling
people derogatory names.

And if you do not at least do what I have suggested, there is about a 
snowball's hope in hell of anybody helping you, as you come across as a 
parasite who wants other people to do his work.

Prove you are not, or go away.

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Tim Chase

daggerdvm wrote:

what are you retarded?  this is not a test you moron, i can ask all
the questions i want about it.


You seem to have forgotten to CC the list.   Let me help show the 
world your mad skillz -- at replying, at programming, at 
orthography, at interpersonal communication...


Sure you can ask all the questions you want...and the newsgroup 
can give all the answers it sees fit.  In all likelihood, your 
professor wanted *you* to solve the problem, not have 
comp.lang.python solve the problem for you.  You got at least two 
answers that solve the problem, but were designed to clearly 
indicated to the professor that you didn't author them yourself.


From my experience teaching students to program, that's the sort 
of problem that 4th or 5th graders (who have been paying 
attention in class) should be able to do with no need to ask for 
help.


Given that you made *no* effort (your post had *zero* code to 
show you had even attempted the problem), you got back far more 
than you put in.


-tkc




--
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread daggerdvm
you brain needs error checking!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Andreas Waldenburger
On Mon, 21 Sep 2009 13:46:31 -0700 (PDT) daggerdvm
dagger...@yahoo.com wrote:

 u don't want to answerthen why post?...get lost.

You're not doing yourself a favor with this attitude, much less
displaying it. You asked a question that you could have solved with 1
hour's worth of reading at most (much less if you're actually attending
some sort of class for this).

I'm not saying you deserve to be mocked, but it is a fact of life that
you get these responses when it is apparent that you put almost no
effort into this problem.

Here's a tip: post to the group your code that you came up with
yourself and explain what gives you trouble. I assure you, the
responses will be more helpful that way.

/W

-- 
INVALID? DE!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Donn
On Monday 21 September 2009 22:49:50 daggerdvm wrote:
 you brain needs error checking!
try:
 return response()
except Troll,e:
 raise dontFeed(anymore=True)

\d
-- 
home: http://otherwise.relics.co.za/
2D vector animation : https://savannah.nongnu.org/projects/things/
Font manager : https://savannah.nongnu.org/projects/fontypython/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread koranthala
On Sep 21, 1:27 am, daggerdvm dagger...@yahoo.com wrote:
  Write the definition of a function  twice , that receives an  int
 parameter and returns an  int that is twice the value of the
 parameter.

 how can i do this

Please note that most mails here are humorous - as should be expected
for a language named after Monty Python.
So, please do not get angry and do take it the way it was intended.

The main problem that everybody sees is that the code you asked is
extremely simple. This causes others to think that you have not
invested any time in getting a solution yourself. Most of us here are
30 years old, and we know from experience that if one does not invest
time and energy in solving issues when we are young, it eventually
leads us to a very unrewarding and unhappy life in the end.

So, even though it looks to you that people are mocking you, it is not
exactly the case. If you do try to get a solution and is unable to do
so, then I am 100% sure that many many people would have provided you
the answer or the way to do so.

Also, since you are young (presumably), it would be good to understand
that if you get it into a flamewar (email or in life), it tends to end
bad for you in the end. Esp, MRAB, Carl Banks, Steven D'Aprano, Tim
Chase etc , whom you flamed, are amongst the most respected people in
this group.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Mel
Tim Roberts wrote:

 daggerdvm dagger...@yahoo.com wrote:

carl banks.you are a dork
 
 What are you, eleven years old?
 
 Look, you asked us to answer for you what is CLEARLY a homework question.
 It is unethical for you to ask that, and it is unethical for us to answer
 it.

Forget ethical.  We can do his homework for him, we can perhaps pass exams 
for him, maybe graduate for him, and then with our luck, he'll get a job in 
our office and we get to do his work for him.

Mel.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Ben Finney
Mel mwil...@the-wire.com writes:

 Tim Roberts wrote:
  Look, you asked us to answer for you what is CLEARLY a homework
  question. It is unethical for you to ask that, and it is unethical
  for us to answer it.

 Forget ethical. We can do his homework for him, we can perhaps pass
 exams for him, maybe graduate for him, and then with our luck, he'll
 get a job in our office and we get to do his work for him.

+1 QOTW

-- 
 \   “Special today: no ice cream.” —mountain inn, Switzerland |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Mahmoud Abdelkader
http://codingforums.com/showthread.php?s=e26b8b0aabc69745ef24a855b1a0fc83t=177529

It seems that this dude really is looking for how to double a variable...


hi looking for help catching up in a class and overall to get me better than
i am now. I can pay you by the week or per hour.

everything can be done by email i will ask you questions and send you simple
questions like:

how to double a variables value i.e: def double(x):
return (x * 2)

ect. you can post here or send me an email at ***...@aol.com


On Tue, Sep 22, 2009 at 9:01 AM, Mel mwil...@the-wire.com wrote:

 Tim Roberts wrote:

  daggerdvm dagger...@yahoo.com wrote:
 
 carl banks.you are a dork
 
  What are you, eleven years old?
 
  Look, you asked us to answer for you what is CLEARLY a homework question.
  It is unethical for you to ask that, and it is unethical for us to answer
  it.

 Forget ethical.  We can do his homework for him, we can perhaps pass exams
 for him, maybe graduate for him, and then with our luck, he'll get a job in
 our office and we get to do his work for him.

Mel.


 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Grant Edwards
On 2009-09-22, Mel mwil...@the-wire.com wrote:
 Tim Roberts wrote:

 daggerdvm dagger...@yahoo.com wrote:

carl banks.you are a dork
 
 What are you, eleven years old?
 
 Look, you asked us to answer for you what is CLEARLY a homework question.
 It is unethical for you to ask that, and it is unethical for us to answer
 it.

 Forget ethical.  We can do his homework for him, we can perhaps pass exams 
 for him, maybe graduate for him, and then with our luck, he'll get a job in 
 our office and we get to do his work for him.

No, no, no.  The plan is to do his homework for him so that
he's incompetent when he graduates and won't be competition for
the rest of us who did do our homework.

-- 
Grant Edwards   grante Yow! ... the HIGHWAY is
  at   made out of LIME JELLO and
   visi.commy HONDA is a barbequeued
   OYSTER!  Yum!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Hyuga
On Sep 22, 9:57 am, Grant Edwards inva...@invalid.invalid wrote:
 On 2009-09-22, Mel mwil...@the-wire.com wrote:

  Tim Roberts wrote:

  daggerdvm dagger...@yahoo.com wrote:

 carl banks.you are a dork

  What are you, eleven years old?

  Look, you asked us to answer for you what is CLEARLY a homework question.
  It is unethical for you to ask that, and it is unethical for us to answer
  it.

  Forget ethical.  We can do his homework for him, we can perhaps pass exams
  for him, maybe graduate for him, and then with our luck, he'll get a job in
  our office and we get to do his work for him.

 No, no, no.  The plan is to do his homework for him so that
 he's incompetent when he graduates and won't be competition for
 the rest of us who did do our homework.

Well, while they may not be as much competition come promotion time, I
think Mr. Finney had it right that these people *do* still somehow get
hired, and then the rest of us end up having to do enough work for
multiple people.  Sometimes spending more time redoing other peoples'
shoddy work than it would have taken to do ourselves in the first
place.  Annoying for the programmer, but really bad for business.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Xavier Ho
On Tue, Sep 22, 2009 at 11:58 PM, Mahmoud Abdelkader
mabdelka...@gmail.comwrote:

 hi looking for help catching up in a class and overall to get me better
 than i am now. I can pay you by the week or per hour.


Wow. I'd feel guilty getting paid doing that. Sounds all too easy.

I hope he is actually learning, not just thinking that money will solve all
his problems.

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread Carl Banks
On Sep 20, 1:27 pm, daggerdvm dagger...@yahoo.com wrote:
  Write the definition of a function  twice , that receives an  int
 parameter and returns an  int that is twice the value of the
 parameter.

 how can i do this

Simple:

Once you define the function, copy it using your editor commands,
then paste it right below the original.


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread Tim Chase

Steven D'Aprano wrote:

Write the definition of a function  twice , that receives an  int
parameter and returns an  int that is twice the value of the parameter.

how can i do this


Yes, that certainly is an easy question.

Here's my solution:

class MultiplierFactory(object):

[snip a marvel of abstruse code]


twice = MultiplierFactory(2)()

It needs some error checking, but otherwise should work.


Tsk...no docstrings?  no unit tests or doctests?  no parameter 
validation?  no copyright notice?  no revision-tracking nor 
authorship comments?  what sort of bad example are you setting 
here?  You want this kid to fail?!  With such poor instruction, 
it's no wonder the economy is going to shambles, the educational 
system is falling apart, there's global warming, terrorism, spam, 
and reality television. Your piteous code make Paris Hilton cry. 
[shakes head in disappointment]


;-)

-tkc





--
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread daggerdvm
u don't want to answerthen why post?...get lost.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread daggerdvm
carl banks.you are a dork
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread Ethan Furman

daggerdvm wrote:

u don't want to answerthen why post?...get lost.


On the contrary!  We *do* want to answer.  Prizes are awarded based on 
the most outlandish yet correct answer, on the most literal answer, and 
on the funniest answer!


Ridiculous questions like yours are what make the daily checking of the 
mailing list worth while.


Now, if you have a _real_ question, that's not homework, check out 
http://catb.org/~esr/faqs/smart-questions.html and then try again.


Happy Coding!

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread Sean DiZazzo
On Sep 21, 1:46 pm, daggerdvm dagger...@yahoo.com wrote:
 u don't want to answerthen why post?...get lost.

I eat children...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread Steven D'Aprano
On Mon, 21 Sep 2009 13:50:23 -0500, David C Ullrich wrote:

 But you actually want to return twice the value. I don't see how to do
 that.

What?

Seriously? You're not just yanking the OP's chain???


-- 
Steven
who normally does quite well detecting sarcasm in writing
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread Tim Chase

But you actually want to return twice the value. I don't see
how to do that.



Ah, I think I see...returning more than once is done with the 
yield keyword:


  def f(param):
yield param
yield param

That returns twice the integer parameter... :-D

However, the OP was instructed to Write the definition of a 
function twice which means I'd have to copy  paste the final 
function definition a second time to make sure it was done twice 
(as Carl suggested).


Then again as David notices, the subject lines asks how to double 
a variable, in which case one might want


  import struct
  def f(param):
return struct.pack('f', param)

which doubles the parameter... :-S

-tkc




--
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread Grant Edwards
On 2009-09-21, David C Ullrich dullr...@sprynet.com wrote:
 On Sun, 20 Sep 2009 13:27:07 -0700, daggerdvm wrote:

 Write the definition of a function  twice , that receives an  int
 parameter and returns an  int that is twice the value of the parameter.
 
 how can i do this

 I don't think this can be done in Python.

 Looking at the Subject line I thought your problem was going
 to be easy: There's only one float type in Python, so at least
 in most implementations simply converting to float will
 suffice to double a variable.

 But you actually want to return twice the value. I don't see
 how to do that.

It's easy:

def twice(i):
return i
return i

-- 
Grant

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-21 Thread Tim Roberts
daggerdvm dagger...@yahoo.com wrote:

carl banks.you are a dork

What are you, eleven years old?

Look, you asked us to answer for you what is CLEARLY a homework question.
It is unethical for you to ask that, and it is unethical for us to answer
it.

As others have said, show us what you TRIED, and we can help you make it
work.
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


easy question, how to double a variable

2009-09-20 Thread daggerdvm
 Write the definition of a function  twice , that receives an  int
parameter and returns an  int that is twice the value of the
parameter.

how can i do this
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-20 Thread MRAB

daggerdvm wrote:

 Write the definition of a function  twice , that receives an  int
parameter and returns an  int that is twice the value of the
parameter.

how can i do this


That's a very basic question. Try a tutorial.
--
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-20 Thread Tim Chase

daggerdvm wrote:

 Write the definition of a function  twice , that receives an  int
parameter and returns an  int that is twice the value of the
parameter.

how can i do this


Read over your textbook and the notes you took in class -- I'm 
sure therein you'll find how to define functions, how to specify 
parameters, how to return values, and how to do basic arithmetic 
operations.  You can also hit up python.org and 
diveintopython.org for more reading if you need.


I'll give you a hint:  If you use

  twice = lambda x: int(x**2/(0.5*x))

I suspect your professor will flunk you for cheating.

-tkc




--
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-20 Thread Steven D'Aprano
On Sun, 20 Sep 2009 13:27:07 -0700, daggerdvm wrote:

 Write the definition of a function  twice , that receives an  int
 parameter and returns an  int that is twice the value of the parameter.
 
 how can i do this

Yes, that certainly is an easy question.

Here's my solution:

class MultiplierFactory(object):
def __init__(self, factor=1):
self.__factor = factor
@property
def factor(self):
return getattr(self, '_%s__factor' % self.__class__.__name__)
def __call__(self, factor=None):
if not factor is not None is True:
factor = self.factor
class Multiplier(object):
def __init__(self, factor=None):
self.__factor = factor
@property
def factor(self):
return getattr(self, 
'_%s__factor' % self.__class__.__name__)
def __call__(self, n):
return self.factor*n
Multiplier.__init__.im_func.func_defaults = (factor,)
return Multiplier(factor)

twice = MultiplierFactory(2)()


It needs some error checking, but otherwise should work.


Ever-helpful-ly y'rs,



-- 
Steven

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-20 Thread Xavier Ho
On Mon, Sep 21, 2009 at 6:27 AM, daggerdvm dagger...@yahoo.com wrote:

  Write the definition of a function  twice , that receives an  int
 parameter and returns an  int that is twice the value of the
 parameter.

 how can i do this


I thought it was easier to implement this twice function than to find this
mailing list. Aren't you being a little lazy? =]

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list