Question

In: Computer Science

def DMStoDD(degree, minutes, seconds): dd = abs(degree) + abs(minutes)/60 + abs(seconds)/3600 if degree > 0: return...

def DMStoDD(degree, minutes, seconds):
         
        dd = abs(degree) + abs(minutes)/60 + abs(seconds)/3600

        if degree > 0:
                return dd
        else:
                return -dd

print(DMStoDD(-30, 30, 00))
In this script, add a main program that collects DD or DMS input from the user, then converts it to the other form and reports the converted value.
Directions: The main program needs to gather a string from the keyboard using input() and detect whether it is DD or DMS (Hint: use the split function). Then it must pass the proper DD or DMS values to the functions above to convert.

The DMS input is separated by comma and contains no space. The degree field could be negative to represent a negative value. (E.g. 43,4,23 or -43,4,23)

Solutions

Expert Solution

If you have any doubts, please give me comment...

def DMStoDD(degree, minutes, seconds):

    dd = abs(degree) + abs(minutes)/60 + abs(seconds)/3600

    if degree > 0:

        return dd

    else:

        return -dd

def DDtoDMS(dd):

    degree = int(abs(dd))

    minutes = int((abs(dd)-degree)*60)

    seconds = (abs(dd) - degree - minutes/60) * 3600

    if(dd<0):

        degree = -degree

    return "%d,%d,%d"%(degree, minutes, seconds)

inp = input("Enter input: ")

d = inp.split(",")

if len(d)==3:

    print(DMStoDD(int(d[0]), int(d[1]), int(d[2])))

else:

    print(DDtoDMS(float(d[0])))


Related Solutions

Need to modify the below code to return the time in minutes instead of seconds. (Using...
Need to modify the below code to return the time in minutes instead of seconds. (Using Python 2.7.6 ) def numberPossiblePasswords(numDigits, numPossiblePerDigit):     numPasswords = numPossiblePerDigit**numDigits     return numPasswords def maxSecondsToCrack(numPossiblePasswords, secPerAttempt):     time = numPossiblePasswords*secPerAttempt     return time nd = int(input("How many digits long is the passcode? "))       nc = int(input("How many possible characters are there per digit? ")) secondsPerAttempt = .08 npp = numberPossiblePasswords(nd, nc) totalSeconds = maxSecondsToCrack(npp, secondsPerAttempt) print("It will take you " + str(totalSeconds) + "...
def mystery(L, x): if L==[]: return False if L[0] == x: return True L.pop(0) return mystery(L,...
def mystery(L, x): if L==[]: return False if L[0] == x: return True L.pop(0) return mystery(L, x) What is the input or length size of the function mystery? What is the final output of mystery([1,3,5,7], 0)? Explain in one sentence what mystery does? What is the smallest input that mystery can have? Does the recursive call have smaller inputs? Why? Assuming the recursive call in mystery is correct, use this assumption to explain in a few sentences why mystery is...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2:...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2: return 2 if n == 3: return 6 if n == 4: return 4 * annoying_factorial(3) if n == 5: return 5 * annoying_factorial(4) if n == 6: return 6 * annoying_factorial(5) else: return n * annoying_factorial(n-1) def annoying_fibonacci(n): if n==0: return 0 if n==1: return 1 if n==2: return 1 if n==3: return 2 if n==4: return annoying_fibonacci(4-1)+annoying_fibonacci(4-2) if n==5: return annoying_fibonacci(5-1)+annoying_fibonacci(5-2) if...
def binsearch(a): if len(a) == 1: return a[0] else: mid = len(a)//2 min1 = binsearch(a[0:mid]) min2...
def binsearch(a): if len(a) == 1: return a[0] else: mid = len(a)//2 min1 = binsearch(a[0:mid]) min2 = binsearch(a[mid:len(a)]) if min1 < min2: return min1 else: return min2 What is the time complexity for the function? include derivative steps to your answer
The functions are tested in the following main(): def recSum1(somelist): if len(somelist) == 1: return somelist[0]...
The functions are tested in the following main(): def recSum1(somelist): if len(somelist) == 1: return somelist[0] else: a = recSum1(somelist[:len(somelist)//2]) b = recSum1(somelist[len(somelist)//2:]) return a + b def recSum2(somelist): if len(somelist) == 1: return somelist[0] else: return somelist[0] + recSum2(somelist[1:]) import random def main(): N = 100 myList = [random.randint(-500, 500) for i in range(N)] print(myList) print("The sum of the numbers is: " + str(sum(myList))) print("The sum of the numbers using recSum1 is: " + str(recSum1(myList))) print("The sum of the...
from PIL import Image def stringToBits(string):     return str(bin(int.from_bytes(string.encode(), 'big')))[2:] def bitsToString(bits):     if bits[0:2] != '0b':         bits.
from PIL import Image def stringToBits(string):     return str(bin(int.from_bytes(string.encode(), 'big')))[2:] def bitsToString(bits):     if bits[0:2] != '0b':         bits = '0b' + bits     value = int(bits, 2)     return value.to_bytes((value.bit_length() + 7) // 8, 'big').decode() def writeMessageToRedChannel(file, message):     image = Image.open(file)     width, height = image.size     messageBits = stringToBits(message)     messageBitCounter = 0     y = 0     while y < height:         x = 0         while x < width:             r, g, b, a = image.getpixel((x, y))             print("writeMessageToRedChannel: Reading pixel %d, %d - Original values (%d, %d, %d, %d)"...
class employee: name = str('')    hourlyWage=0 hoursWorked=0 def getPayment(self): payment=self.hourlyWage*self.hoursWorked return payment    class payrollApp(employee):...
class employee: name = str('')    hourlyWage=0 hoursWorked=0 def getPayment(self): payment=self.hourlyWage*self.hoursWorked return payment    class payrollApp(employee):    def printStatement(self): print('The Employee Name is ' + self.name) print('The Employee Hourly wage is ' + str(self.hourlyWage)) print('No of hours worked ' + str(self.hoursWorked)) print('The Employee payment is ' + str(employee.getPayment(self))) emp = [] x=0 a=True totalPayout=0 while a:    emp.append(payrollApp()) emp[x].name=input("Enter Employee Name: ") emp[x].hourlyWage=int(input("Enter hourly wage: ")) emp[x].hoursWorked=int(input("Enter No of hours worked: ")) totalPayout= totalPayout + (emp[x].hourlyWage * emp[x].hoursWorked) print("\n") x=x+1...
Compute the expected return for the following investment State of nature Probability Return Boom 25% 20% Average 60% 8% Recession 15% 0%
Compute the expected return for the following investmentState of nature Probability ReturnBoom 25% 20%Average 60% 8%Recession 15% 0%
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT