Created
April 9, 2020 16:47
-
-
Save roman-on/bcdd77ee17ff78972d3d385f82758c03 to your computer and use it in GitHub Desktop.
Distance
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
""" | |
Write a function called distance | |
The function receives three integers: num1, num2, num3. | |
The function returns True if both conditions are met: | |
1. One of the numbers num2 or num3 is "close" to num1. "Close" = absolute distance 1. | |
2. One of the numbers num2 or num3 is "far" from the other two numbers. "Far" = absolute distance 2 or higher. | |
>>> distance(1, 2, 10) | |
True | |
>>> distance(4, 5, 3) | |
False | |
""" | |
def distance(num1, num2, num3): | |
near = (abs(num1 - num2) == 1 or abs(num1 - num3) == 1) | |
far = ((abs(num2 - num3) >= 2) and (abs(num2 - num1) >= 2) or (abs(num3 - num2) >= 2) and (abs(num3 - num1) >= 2)) | |
if near and far: | |
print (True) | |
else: | |
print (False) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment