easy question, how to double a variable

Grant Edwards invalid at invalid.invalid
Tue Sep 22 05:09:22 CEST 2009


On 2009-09-21, David C Ullrich <dullrich at 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




More information about the Python-list mailing list