[Tutor] variables within function - wha?

George Gates ggates@appliedtheory.com
Thu, 19 Jul 2001 11:17:02 -0400


The problem is "type" is a built in function.  Change the name of that=
 variable. Also, you are not passing or testing the type as a string. ie:

def filter(cc,rpm,t):
	cid=3Dcc/16.387
	ocg=3D(cid*rpm)/20839
	foam=3Docg*1.3767
	paper=3Docg*1.2181
	if t=3D=3D'paper':
		return paper,
	elif t=3D=3D'foam':
		return foam,
	else:
		return ocg


>>> filter(1800,7000,'foam')
(50.7964695628,)
>>> filter(1800,7000,'paper') 
(44.9445627765,)
>>> 

*********** REPLY SEPARATOR  ***********

On 7/19/01 at 10:17 AM kromag@nsacom.net wrote:

>I am trying to get a function to perfrom simple calculations based on 3 
>values.
>
>-----------------------------------
>
>def filter(cc,rpm,type):
>	cid=3Dcc/16.387
>	ocg=3D(cid*rpm)/20839
>	foam=3Docg*1.3767
>	paper=3Docg*1.2181
>	if type=3D=3Dpaper:
>		return paper,
>	elif type=3D=3Dfoam:
>		return foam,
>	else:
>		return ocg
>
>-----------------------------------
>
>I can't figure out why:
>
>>>> filter(1800,7000,'foam')
>Traceback (innermost last):
>  File "<pyshell#1>", line 1, in ?
>    filter(1800,7000,foam)
>NameError: There is no variable named 'foam'
>>>> 
>
>occours. Have I been inhaling too much brake cleaner?
>
>d
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


George H. Gates
System Administrator - OSOS Implementation

Phone: (315) 453-2912 x5671
Email: ggates@appliedtheory.com
Web: http://ggates.appliedtheory.com