Need quick help with Python code I am getting input from a u

Need quick help with Python code.

I am getting input from a user for latitude and longitude (lat, long). There are some exceptions that it won\'t appect or it should prompt the user to re-enter.

It must be sperated by a comma (lat, long), lat value must be between -90 and 90, long value must be between -180 and 180. And it must be a number (float or whole number).

If you can add comments to the code I would appericate it and thanks for any help!

Solution

while True:
   #This reads the input
   st = raw_input(\"Please enter latitude and longitude separated by a comma:\")
   st = st.split(\',\')
   st[0] = float(st[0])
   st[1] = float(st[1])
   if(st[0] < -90 or st[0]>90):
       print(\'Latitude value must be between -90 and 90\')
       continue
   if(st[1] < -180 or st[1] > 180):
       print(\'Longitude value must be between -180 and 180\')
       continue
   print(\"Latitude is \"+str(st[0]))
   print(\"Longitude is \"+str(st[1]))
   break

Need quick help with Python code. I am getting input from a user for latitude and longitude (lat, long). There are some exceptions that it won\'t appect or it s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site