Created
January 6, 2020 11:59
-
-
Save Tedezed/375640e1bd42eab33a925c069bb0c6f9 to your computer and use it in GitHub Desktop.
Calculate distance between two numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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