a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment
veen  ·  3800 days ago  ·  link  ·    ·  parent  ·  post: Pubski: September 24, 2014

Oh absolutely. Here's my finished, neat-ified code. Could be muuuch more simple but this was an assignment to show that I can, in fact, write a script.

  LatCoord = input('Enter the latitude coordinate here: ')
  LongCoord = input('Enter the longitude coordinate here: ')

  #Puts the coordinates in a list
  coordinate = [LatCoord, LongCoord]

  #Check if the coordinates are valid, and if it isn't, end script.
  if abs(LongCoord) > 180 or abs(LatCoord) > 90:
    print: 'Invalid coordinate!'
    break

  #Loop to convert the list of coordinates
  for x in coordinate:
    D = int(x)                  #Calculate the Degree

    decimal1  = abs(x - D)      #Calculate the absolute Minutes (only D can be pos/neg)
    minutes = 60 * decimal1     #from the remaining decimals
    M = int(minutes)

    decimal2 = minutes - M      #Calculate the Seconds
    seconds = 60 * decimal2     #from the remaining decimals
    S = int(round(seconds))     #and round the number

    if x == LatCoord:           #Checks if the num is lat or long
      print "Your Latitude is: ", D, M, S
    else:
      print "Your Longtitude is: ", D, M, S