[Tutor] return integer from function

Brian van den Broek brian.van.den.broek at gmail.com
Wed Feb 22 14:13:25 CET 2012


On 22 February 2012 12:57, David Craig <dcdavemail at gmail.com> wrote:
> Hi,
> I have a function that calculates the distance between two points on a
> sphere. It works but I cant get it to return a float for use in another
> script. Anyone know how I do that??
>

<snip code>

>    cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) +
>           math.cos(phi1)*math.cos(phi2))
>    arc = math.acos( cos )
>    type(arc)
>    arc = arc*6378.1
>    #print str(arc*6378.1)+' km'
>    # Remember to multiply arc by the radius of the earth
>    # in your favorite set of units to get length.
>    return arc


Hi David,

I'm a bit puzzled. A few lines above the return, you have 'type(arc)'.
Try replacing that with 'print type(arc)' and also include 'print
type(arc)' immediately above your return. I think you will find that
the code you posted does return a float.

Best,

Brian vdB


More information about the Tutor mailing list