Skip to content

Instantly share code, notes, and snippets.

@vicvicvar
Forked from jspblm/course_calucation
Created November 10, 2017 15:04
Show Gist options
  • Save vicvicvar/574c6a86e6787cbd6609ac07e204223c to your computer and use it in GitHub Desktop.
Save vicvicvar/574c6a86e6787cbd6609ac07e204223c to your computer and use it in GitHub Desktop.
""" A simple script to calculate the diference within two courses """
def course_delta(c1, c2):
""" Calculate the diference within two consecutive courses """
if c2 < c1:
# The function expects that c2 is always greater than c1
temp = c2
c2 = c1 # switch the values of c1 and c2
c1 = temp
delta = c2 - c1
if delta > 180:
# When the diference is greater than 180 degrees calculate the complement of course two. (base on a 360 degrees)
d = 360 - c2
delta = d + c1
return delta
else:
return delta
################################ When course_two - course_one < 180 degrees
course_one = 10
course_two = 80
course_change = course_delta(course_one, course_two)
print('course_change = %s ' % course_change)
validation = 60
if course_change >= validation:
print('The difference within course one and course two is greater than %s, When course_two - course_one < 180 degrees ' % (validation,))
################################ When course_two - course_one > 180 degrees
course_one = 25
course_two = 320
course_change = course_delta(course_one, course_two)
print('course_change = %s' % course_change)
validation = 60
if course_change >= validation:
print('The difference within course one and course two is greater than %s, When course_two - course_one > 180 degrees ' % (validation,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment