easy question, how to double a variable

M

Mel

Tim said:
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.
 
G

Grant Edwards

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.
 
H

Hyuga

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.
 
S

Steven D'Aprano

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".
 
C

Casey Webster

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
 
I

Iain King

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.


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
 
P

Pablo Torres N.

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)))
 
C

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))
 
T

Tom Kermode

def twice(parameter = 2)
return 4

2009/9/20 daggerdvm said:
 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top