Question on Python Function

Alister alister.ware at ntlworld.com
Mon May 24 16:45:42 EDT 2010


On Mon, 24 May 2010 13:15:01 -0700, joy99 wrote:

> Dear Group,
> 
> I have a small question on function.
> 
> If I write two functions like the following:
> 
> IDLE 2.6.5
>>>> def function1(n):
> 	element1=5
> 	element2=6
> 	add=element1+element2
> 	print "PRINT THE ADDITION",add
> 
> 
>>>> def function2(n):
> 	element3=7
> 	element4=22
> 	mult=element3*element4
> 	print "PRINT THE MULTIPLICATION",mult
> 
> Can I now write a third function where the above two functions can be
> passed as argument or parameter?
> 
> Best Regards,
> Subhabrata.
> 
> NB: As I copied the code from IDLE to MS-Word befor posting here, codes
> may have slight indentation errors.

I don't quite see the point of your functions as they do not use their 
parameters in any way, but you need to set a return value

 IDLE 2.6.5
>>> def function1(n):
 	element1=5
 	element2=6
 	add=element1+element2
 	return add
 
>>> def function2(n):
 	element3=7
 	element4=22
 	mult=element3*element4
	return mult

>>> def function3(x,y):
	print "add= %s mult=%s" % (x , y)

>>>function3(function1(1),funtcion2(2))

	
-- 
Your digestive system is your body's Fun House, whereby food goes on a 
long,
dark, scary ride, taking all kinds of unexpected twists and turns, being
attacked by vicious secretions along the way, and not knowing until the 
last
minute whether it will be turned into a useful body part or ejected into 
the
Dark Hole by Mister Sphincter.  We Americans live in a nation where the
medical-care system is second to none in the world, unless you count maybe
25 or 30 little scuzzball countries like Scotland that we could vaporize 
in
seconds if we felt like it.
		-- Dave Barry, "Stay Fit & Healthy Until You're Dead"



More information about the Python-list mailing list