Detecting Valid Latitude and Longitude Pairs

  • + 0 comments

    PYTHON

    N = int(input())
    while N:
        N = N - 1
        s = input()
        m = re.search(r'[+-]?(?P<xAxis>\d+(\.\d+)?), [+-]?(?P<yAxis>\d+(\.\d+)?)', s)
        if m:
            x = m['xAxis']
            xf = float(x)
            y = m['yAxis']
            yf = float(y)
            if x[0] == '0' and len(x) > 1 and x[1] != '.':
                print("Invalid")
                continue
            if y[0] == '0' and len(y) > 1 and y[1] != '.':
                print("Invalid")
                continue
            if(xf > 90 or yf > 180) :
                print("Invalid")
            else:
                print("Valid")
        else:
            print("Invalid")