I have this code that I need to change to pass the below assert test:
def degrees_to_dms(degrees_fraction):
''' Convert degrees to degree, minute, second 3-tuples'''
degrees = int(degrees_fraction)
minutes = abs(degrees_fraction - degrees) * 60.0
seconds = np.round((degrees_fraction - degrees - minutes/60.0) * 3600.0, 2)
return (degrees, abs(minutes), abs(seconds))
def dms_to_degrees(d,m,s):
''' Convert degrees, minutes, seconds to fractional degrees'''
return float(d)+float(m/60.00)+float(s/3600.00)
And it needs to pass this assert test:
assert dms_to_degrees(*degrees_to_dms(42.2833333333)) == 42.28333333333333
The only difference is that there are four more 3's in the expected outcome. In iterating through each step of the process, it looks like the addition of float(d) with float(m/60.00) in dms_to_degrees leads to a rounding of the decimal places. I'd like to make it so that it outputs those extra 3's. I also noticed that m/60 = 0.2833333332999999, so I don't know why they expect the 2999999 to become all 3's anyways. But maybe there is a different approach needed altogether.
Thank you.