python can't pass arguements from a function to another function?

Reply

Join Date: Jun 2009
Posts: 39
Reputation: fallopiano is an unknown quantity at this point 
Solved Threads: 4
fallopiano's Avatar
fallopiano fallopiano is offline Offline
Light Poster

python can't pass arguements from a function to another function?

 
0
  #1
Aug 21st, 2009
Hi all. I'm working on a python file that will be included in a project I am working on. Unfortunately, I ran into some problems when it came to passing arguments from a function, to another function. Let me explain; I have two functions: dist and return_mouse_angle. dist returns the distance between two points, and return_mouse_angle returns the slope of two points...

  1. def dist(p1,p2):
  2. # a^2 + b^2 = c^2
  3. return math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 )
  4.  
  5. def return_mouse_angle(mouse_pos,object_pos):
  6. radians = math.asin( dist(mouse_pos,object_pos)/
  7. dist(mouse_pos,[mouse_pos[0],object_pos[1]]) )
  8. degress = math.degrees( radians )
  9. print degrees

for example, when I run
  1. return_mouse_slope( [100,100],[154,129])

I get this error:

  1. Traceback (most recent call last):
  2. File "<pyshell#59>", line 1, in <module>
  3. return_mouse_slope( [100,100],[154,129])
  4. File "C:/Documents and Settings/Owner/Desktop/rewrite project warp/lib/maths.py", line 15, in return_mouse_slope
  5. dist(mouse_pos,[mouse_pos[0],object_pos[1]]) )
  6. ValueError: math domain error

I'm not able to pass mouse_pos[0] and object_pos[1] to the dist function. Is python not able to pass arguments (in this case, a list) from a function to another function?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,046
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 263
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: python can't pass arguements from a function to another function?

 
0
  #2
Aug 21st, 2009
Originally Posted by fallopiano View Post
  1. Traceback (most recent call last):
  2. File "<pyshell#59>", line 1, in <module>
  3. return_mouse_slope( [100,100],[154,129])
  4. File "C:/Documents and Settings/Owner/Desktop/rewrite project warp/lib/maths.py", line 15, in return_mouse_slope
  5. dist(mouse_pos,[mouse_pos[0],object_pos[1]]) )
  6. ValueError: math domain error
I'm not able to pass mouse_pos[0] and object_pos[1] to the dist function. Is python not able to pass arguments (in this case, a list) from a function to another function?
Try to figure out how to use the dist function in the interpreter and then implement it inside your function. The ValueError is telling you that what you're trying to do is unsupported by dist.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 39
Reputation: fallopiano is an unknown quantity at this point 
Solved Threads: 4
fallopiano's Avatar
fallopiano fallopiano is offline Offline
Light Poster

Re: python can't pass arguements from a function to another function?

 
0
  #3
Aug 21st, 2009
but how do i do that? i tried putting the dist function in return_mouse_angle:
  1. def return_mouse_slope(mouse_pos,object_pos):
  2. p1 = mouse_pos
  3. p2 = object_pos
  4. p3 = [mouse_pos[0],object_pos[1]]
  5. # sin^-1 and distance formula
  6. radians = math.asin( math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 )/
  7. math.sqrt( (p3[0]-p1[0])^2+(p3[1]-p1[1])^2 ) )
  8.  
  9. degress = math.degrees( radians )
  10. print degrees

but I still got
  1. Traceback (most recent call last):
  2. File "<pyshell#16>", line 1, in <module>
  3. return_mouse_slope([100,100],[50,150])
  4. File "C:\Documents and Settings\Owner\Desktop\rewrite project warp\lib\maths.py", line 18, in return_mouse_slope
  5. radians = math.asin( math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 )/
  6. ValueError: math domain error
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,273
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 175
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: python can't pass arguements from a function to another function?

 
0
  #4
Aug 21st, 2009
Try this:
print(10^2)
print(10**2)
Last edited by sneekula; Aug 21st, 2009 at 5:18 pm.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC