- Joined
- Sep 16, 2009
- Messages
- 1
- Reaction score
- 0
This is my first script I have to write for python and I'm having a problem. My assignment is to write a script that takes geographic coordinates in Decimal Degrees and convert it to Degrees, Minutes, Seconds. Basically I need to be able to take a decimal degree input (such as 42.5678) and convert it. I'm trying to find out how to seperate the integer (42) from the decimal (.5678). In this example I need the decimals to manipulate (multiply .5678 * 60 for Minutes) and take the decimal from the minutes result and lastly (multiply by 3600 for seconds).
I used the math.floor function to round the number down to get degrees, and I feel that subtracting the result of this function from the original decimal degree input would be easiest to get just the decimal, but I am getting a syntax error "'float' object is unsubscriptable." I think it has to do with the data type and I have been searching for a couple of hours through the Python documentation and haven't found anything helpful. Any help or suggestions are appreciated.
Here is what I have so far:
# Import System and Math Modules
import sys, math
# Input Argument (in Decimal Degrees, ex: 42.5678)
decdegrees = float(sys.argv[1])
# Conversion
degrees = math.floor(decdegrees) # to return whole 42
minutes = (decdegrees - degrees) * 60
#seconds =
# Display Result
#print degrees " " minutes " " seconds " "
print degrees " " minutes
I used the math.floor function to round the number down to get degrees, and I feel that subtracting the result of this function from the original decimal degree input would be easiest to get just the decimal, but I am getting a syntax error "'float' object is unsubscriptable." I think it has to do with the data type and I have been searching for a couple of hours through the Python documentation and haven't found anything helpful. Any help or suggestions are appreciated.
Here is what I have so far:
# Import System and Math Modules
import sys, math
# Input Argument (in Decimal Degrees, ex: 42.5678)
decdegrees = float(sys.argv[1])
# Conversion
degrees = math.floor(decdegrees) # to return whole 42
minutes = (decdegrees - degrees) * 60
#seconds =
# Display Result
#print degrees " " minutes " " seconds " "
print degrees " " minutes