0

Here is my code which returns the timezone a set of coordinates are in. The IDE is telling me that a colon is expected somewhere in the nested if statement. The first if statement seems to be fine. and when I take out the negative signs in the other if statements they work fine. Thanks for any help!

def findTimeZone(coordinatesString):
    coordinates = coordinatesString.split(",")
    if 24.660845 <= float(coordinates[0]) <= 49.189787:
        if ‐87.518395 <= float(coordinates[1])  < ‐67.44457:
            return "eastern"
        elif ‐87.518395 <= float(coordinates[1]) < ‐101.998892:
            return "central"
        elif ‐101.998892 <= float(coordinates[1]) < ‐115.236428:
            return "mountain"
        elif ‐115.236428 <= float(coordinates[1]) <= ‐125.242264:
            return "pacific"

I could just assign each float to a variable but I would like to know why this is causing an error, Thanks.

2
  • Can you paste the exact error you are seeing. Commented Nov 8, 2019 at 5:13
  • I think this is an issue with encoding. Try writing the - manually in python IDLE. Commented Nov 8, 2019 at 5:22

4 Answers 4

1

Are you copy pasting the code from some document. In your code I could see the "-" negative symbol was some other special character

Try writing the "-" using your keyboard. This happens usualy due to unicode conversion issues because "-" symbol may look the same but act different

Sign up to request clarification or add additional context in comments.

Comments

1

Those aren't -'s like you think. Replace whatever it is you are using for the negative sign with an actual -.

Comments

0

As an aside, and in addition to what both the other answers have said, your logic is wrong:

Use this instead:

def findTimeZone(coordinatesString):
    coordinates = coordinatesString.split(",")
    if 24.660845 <= float(coordinates[0]) <= 49.189787:
        if -87.518395 <= float(coordinates[1])  < -67.44457:
            return "eastern"
        elif -87.518395 > float(coordinates[1]) >= -101.998892:
            return "central"
        elif -101.998892 > float(coordinates[1]) >= -115.236428:
            return "mountain"
        elif -115.236428 > float(coordinates[1]) >= -125.242264:
            return "pacific"

Comments

0

Let me try to help. I think you are getting error invalid character in identifier

Identifiers or “names” can have only the following characters in python

-> a to z (alphabets lowercase)

-> A to Z (alphabets uppercase)

-> 0 to 9 (digits)

-> _ (underscore)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.