Skip to content

Instantly share code, notes, and snippets.

@Tedezed
Created January 6, 2020 11:59
Show Gist options
  • Save Tedezed/375640e1bd42eab33a925c069bb0c6f9 to your computer and use it in GitHub Desktop.
Save Tedezed/375640e1bd42eab33a925c069bb0c6f9 to your computer and use it in GitHub Desktop.
Calculate distance between two numbers
def to_positive(input):
if (input < 0):
input = input * -1
return input
def to_negative(input):
if (input > 0):
input = input * -1
return input
def distance(init_step, end_step):
if init_step < end_step:
units = to_positive(init_step - end_step)
else:
units = to_negative(end_step - init_step)
return units
print(distance(-10,10))
print(distance(10,-10))
print(distance(-2,2))
print(distance(2,-2))
print(distance(-2,10))
print(distance(-10,2))
print(distance(-10,-2))
print(distance(2,10))
print(distance(10,2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment