# Python Assignment Help

Free GPS python code.

import math
import random

class Point:
def __init__ (self, longitude, latitude):
self.latitude = latitude
self.longitude = longitude

class WayPoint:
def __init__(self, name, p):
self.name = name
self.p = p

def getDistance(self, wp):
R = 6371.0
if (wp.p.longitude > self.p.longitude):
d = (math.acos(math.sin(self.p.latitude) * math.sin(wp.p.latitude) +
math.cos(self.p.latitude) * math.cos(wp.p.latitude) *
math.cos(wp.p.longitude - self.p.longitude)) * R)
else:
d = (math.acos(math.sin(self.p.latitude) * math.sin(wp.p.latitude) +
math.cos(self.p.latitude) * math.cos(wp.p.latitude) *
math.cos(self.p.longitude - wp.p.longitude)) * R)
return d

class Path:
def __init__(self, name):
self.name = name
self.wp =[]

self.wp.append(wayp)
return

def pathRemoveWaypoint(self, wayp):
self.wp.remove(wayp)
return

def getPathLength(self):
l = len(self.wp)
if (l > 0): wayp1 = self.wp[0]
d = 0.0
for x in range(1,l):
wayp2 = self.wp[x]
d = d + wayp1.getDistance(wayp2)
wayp1 = wayp2
return d

def listPath(self):
l = len(self.wp)
for x in range(0,l):
print self.wp[x].name
return

class GPS:
def __init__ (self):
self.currentLocation = Point(0,0)
self.wp = []
self.paths = []

def gpsUpdateCurrentLocation (self):
self.currentLocation = Point(random.random() * 360 - 180,
random.random() * 360 - 180)
return (self.currentLocation)

def gpsSaveWaypoint(self, name):
wayp = WayPoint(name, self.currentLocation)
self.wp.append(wayp)

def gpsListAllWaypoints(self):
print "Saved waypoints:"
l = len(self.wp)
for x in range(0,l):
print self.wp[x].name, self.wp[x].p.longitude, self.wp[x].p.latitude
return

def gpsListAllWaypointNames(self):
print "Saved waypoints:"
l = len(self.wp)
for x in range(0,l):
print self.wp[x].name
return

def gpsListAllPathNames(self):
print "Saved paths:"
l = len(self.paths)
for x in range(0,l):
print self.paths[x].name
return

l = len(self.wp)
wp_found = 0
for x in range(0,l):
if (self.wp[x].name == wp_name):
wayp = self.wp[x]
wp_found = 1
if wp_found == 0:
print "Invalid waypoint: ", wp_name
return

l = len(self.paths)
for x in range(0,l):
if (self.paths[x].name == path_name):
return
p = Path(path_name)
self.paths.append(p)
return

def gpsRemoveWaypointFromPath(self, path_name, wp_name):
l = len(self.wp)
found = 0
for x in range(0,l):
if (self.wp[x].name == wp_name):
wayp = self.wp[x]
found = 1
if found == 0:
print "Invalid waypoint: ", wp_name
return

l = len(self.paths)
found = 0
for x in range(0,l):
if (self.paths[x].name == path_name):
self.paths[x].pathRemoveWaypoint(wayp)
found = 1
return
if found == 0:
print "Invaid path name: ", path_name
return

def gpsListPath(self, name):
l = len(self.paths)
found = 0
for x in range(0,l):
if (self.paths[x].name == name):
found = 1
p = self.paths[x]
if found == 0:
print "Invaid path name: ", name
return
p.listPath()
return

def gpsComputeDistance(self, name1, name2):
l = len(self.wp)
found1 = 0
found2 = 0
for x in range(0,l):
if (self.wp[x].name == name1):
wayp1 = self.wp[x]
found1 = 1
if (self.wp[x].name == name1):
wayp2 = self.wp[x]
found2 = 1
if (found1 == 0 or found2 == 0):
print "Invalid waypoint name: ", name1, name2
return 0.0;
return (wayp1.getDistance(wayp2))

def gpsComputePathLength(self, name):
l = len(self.paths)
for x in range(0,l):
if (self.paths[x].name == name):
return (self.paths[x].getPathLength())
print "Invaid path name: ", name
return 0.0

Python Basics Programming Assignment Help
• HTML And Python
• Variables
• Operators
• Controls And Loops
• Functions
• Events
• Error And Exceptions Handling
• Functions
Python Data Structure Programming Assignment Help
• String
• Array
• Stacks
• Queues
• Lists
• RegExp
• Dictionaries
• Graphs
• Input And Output