Create a function `close_compare` that accepts 3 parameters: `a`, `b`, and an optional `margin`. The function should return whether `a` is lower than, close to, or higher than `b`. `a` is "close to" `b` if `margin` is higher than or equal to the difference between `a` and `b`.

When `a` is lower than `b`, return `-1`.

When `a` is higher than `b`, return `1`.

When `a` is close to `b`, return `0`.

If `margin` is not given, treat it as zero.

Example: if `a = 3`, `b = 5` and the `margin = 3`, since `a` and `b` are no more than 3 apart, `close_compare` should return `0`. Otherwise, if instead `margin = 0`, `a` is lower than `b` and `close_compare` should return `-1`.

Assume: `margin >= 0`

Tip: Some languages have a way to make arguments optional.

Difficulty: introductory

Starter code:

def close_compare(a, b, margin=0):
	

Solutions:
def close_compare(a, b, margin = 0):
    return 0 if abs(a - b) <= margin else -1 if b > a else 1

def close_compare(a, b, margin=0):
    if a == b or abs(a - b) <= margin:
        return 0
    if a < b:
        return -1
    if a > b:
        return 1

def close_compare(a, b, margin=0):
    if a-b>margin:
      return 1
    elif b-a>margin:
      return -1
    else:
      return 0

def close_compare(a, b, margin=0):
  # If the absolute value of their difference is no greater than the margin,
  # then they're equal enough.
  if abs(a - b) <= margin:
    return 0;
    
  # They removed the cmp() function in Python 3, so we use this weird-looking expression
  # instead.  This works because arithmetic operations like '-' coerce their operands into
  # numbers.  A boolean operand is coerced into a 1 if it's True or a 0 if it's False.
  # So if a > b, then this expression is equivalent to True - False, which after coercion
  # becomes 1 - 0, which is 1.  Likewise, if a < b, then it's 0 - 1, which is -1.  And if
  # a == b, then it's False - False, which coerces to 0 - 0, which is 0.
  return (a > b) - (a < b)

close_compare=lambda a, b, margin=0: 0 if abs(a-b)<=margin else -1 if a<b else 1

def close_compare(a, b, margin=0):
    return abs(a-b) > margin and (a>b) - (a<b)

from numpy import sign

def close_compare(a, b, margin=0):
    return abs(a-b) > margin and sign(a-b)

def close_compare(a, b, margin=0):
    dif = a-b
    return 0 if abs(dif)<=margin else -1 if dif<0 else 1

close_compare = lambda a,b,m=0: 0 if abs(a-b)<=m else -1*(a<b)+(a>b) 

def close_compare(a, b, margin=0):
    return 0 if margin >= abs(a-b) else 1 if a>b else -1


def close_compare(a, b, margin = 0):
    if abs(a - b) <= margin:
        return 0
    elif a < b:
        return -1
    return 1

def close_compare(a, b, margin=0):
    if abs(a - b) <= margin: return 0
    elif a < b: return -1
    else: return 1

def close_compare(a, b, margin=0):
    return 0 if abs(a - b) <= margin else 1 if a > b else -1

def close_compare(a: int, b: int, margin: int=0) -> int:
    """ Check if `a` is lower than, close to, or higher than `b`. """
    return 0 if (abs(a - b) <= margin if margin else a == b) else 1 if a > b else -1

def close_compare(a, b, margin=0):
    return 0 if abs(a-b) <= margin else [-1,1][a>b]

def close_compare(a, b, margin = 0):
    return (a-b)//abs(a-b) if abs(a-b) > margin else 0

def close_compare(a, b, margin=0):
    return a - b > margin or -(a - b < - margin)

def close_compare(a, b, margin=0):
    return (2 * (a > b) - 1) * (abs(a - b) > margin)

def close_compare(a, b, m=0):
    return [(a>b)-(a<b),0][abs(a-b)<=m]

def close_compare(a, b, m=0):
    return 0 if abs(a - b) <= m else (a > b) - (a < b)

def close_compare(a, b, m=0):
    return -1 if m + a < b else [0,1][m + b < a]

def close_compare(a, b, m=0):
    return -1 if a < b and a - b + m < 0 else [0,1][a > b and m < a-b > 0]

close_compare=lambda a,b,m=0:(a+m>=b)-(a-m<=b)

def close_compare(a, b, margin=0):
    if margin > 0:
        if abs(a - b) <= margin:
            return 0
        else:
            if a - b > 0:
                return 1
            else:
                return -1
    else:
        if a > b:
            return 1
        elif a < b:
            return -1
        else:
            return 0


def close_compare(a, b, margin=None):
    
    if margin is not None:
        if round(abs(a - b),3) <= margin:
            return 0

    if a < b:
        return -1
    elif a > b:
        return 1  

    return 0


def close_compare(a, b, margin=0):
    if margin >= abs(a - b):
        return 0
    elif a - b < 0:
        return -1
    else:
        return 1

def close_compare(a, b, margin=0):
    x = a - b
    if margin >= abs(x):
        return 0
    elif x < 0:
        return -1
    else:
        return 1

def close_compare(a, b, margin=0):
    if a == b or margin >= abs(b-a):
        return 0
    if a < b or margin > abs(a - b):
        return -1
    if a > b or margin < a:
        return 1 
    


def close_compare(a, b, margin=None):
    # None is required when there is optional argument
    if margin == None:
        margin = 0
    # cheking difference between a and b
    result = a - b
    # if close to margin
    if margin >= abs(result):
        return 0
    elif result > 0:
        return 1
    else:
        return -1

def close_compare(a, b, margin=None):
    if margin:
        return 0 if  abs(b-a)<=margin else 1 if a>b else -1
    return -1 if a<b else 1 if a>b else 0

def close_compare(a, b, margin = 0):
    diff = a - b
    if margin >= abs(diff):
        return 0
    return 1 if diff > 0 else -1

def close_compare(a, b, margin = 0):
    if max(a, b) - min(a, b) <= margin:
        return 0
    if a > b:
        return 1
    return -1


def close_compare(a, b, margin=0):
    # close to:
    marginal = abs(a-b)
    if margin >= marginal:
        return 0
    if a < b:
        return -1
    if a > b:
        return 1


print(close_compare(2, 8, ))
pass

def close_compare(a, b, margin=0):
    plus = a + margin
    minus = a - margin
    if (plus > b) and (minus > b):
        return 1
    elif (plus < b) and (minus < b):
        return -1
    else:
        return 0

def close_compare(a, b, margin=0):
    if abs(a - b) > margin:
        return 1 - 2 * (a < b)
    else:
        return 0

def close_compare(a, b, margin = 0):
    prox = a - b
    if abs(prox) <= margin:
        return 0
    elif a > b:
        return 1
    else:
        return -1

def close_compare(a, b, margin=0): # margin = 0  -optional element
    difference = abs(a-b) #difference between a and b
    
    if margin >= difference:  #a is close to b
        return 0
    elif a > b: #a is higher 
        return 1
    elif a < b: #a is lower
        return -1
    
    pass

def close_compare(a, b, margin=0):
    difference = abs(a-b) #difference between a and b
    
    if margin >= difference:  #a is close to b
        return 0
    elif a > b: #a is higher 
        return 1
    elif a < b: #a is lower
        return -1
        
    
    
    pass

def close_compare(a, b, margin=0):
    if a < b and abs(a-b) > margin: return -1
    elif a == b or abs(a-b) <= margin : return 0
    else: return 1

def close_compare(a, b, margin = 0):
    abs(margin)
    if a < b and b - a <= margin:
        return 0
    elif a > b and a - b <= margin:
        return 0
    elif a == b and a - b <= margin:
        return 0
    elif a < b:
        return -1
    else:
        return 1

import math

def close_compare(a, b, margin = 0):
    if -margin <= a-b <= margin:
        return 0
    return 1 if a>b else -1

def close_compare(a, b,margin=0):
    return (-1 if a<b else 1 if a>b else 0 ) if margin==0 else 0 if margin>=abs(a-b) else -1 if (a-b)<margin else 1

def close_compare(a, b, margin=0):
    print(a, b, margin)
    if margin == 0:
        return -1 if a < b else 1 if a != b else 0
    else:
        if a == b or abs(a-b) == margin:
            return 0
        elif a < b:
            return 0 if abs(a-b) <= margin else -1
        elif a > b:
            return 0 if abs(a-b) <= margin else 1

def close_compare(a, b, margin=0):
    if margin >= abs(a - b):
        return 0
    elif a > b:
        return 1
    elif a < b:
        return -1
    elif a == b:
        return 0

def close_compare(a, b, margin=0):
    if margin is not 0 and abs(a-b) <= margin or a == b:
        return 0
    else:
        return -1 if (a < b) else 1

def close_compare(a, b, margin = 0):
    if abs((b - a)) <= margin:
        return 0
    else:
        if b > a:
            return -1
        else:
            return 1


def close_compare(a, b, margin=0):
    if a > b:
        d = a-b
        return 1 if d>margin else 0
    elif b > a:
        d = b-a
        return -1 if d>margin else 0
    else:
        return 0

def close_compare(a, b, margin=0):
        
    if margin==0:
        if a==b:
            return 0
        elif a>b:
            return 1
        elif a<b:
            return -1
        
    elif margin>0:
        if (a-b)>0 and (a-b)<=margin:
            return 0
        elif (a-b)<0 and ((a-b)*-1)==margin:
            return 0
        elif (a-b)<0 and ((a-b)*-1)<=margin:
            return 0
        elif a==b:
            return 0
        elif a>b:
            return 1
        elif (a-b)<0 and (a-b)<=margin:
            return -1

def close_compare(a, b, margin=0):
    l=range(b-margin,b+margin+1)
    if a in l: return 0
    elif a<b: return -1
    else: return 1

import math
def close_compare(a, b, margin=0):
    if math.fabs(a-b) <= margin:
        return 0
    if a<b:
        return -1
    return 1


def close_compare(a, b, margin = 0):
    
    if abs(a-b) <= margin:
        return 0
    elif abs(a-b) > margin and (a-b) < 0:
        return -1
    else:
        return 1

def close_compare(a, b, margin=0):
    difference = abs(b-a)
    if a < b and difference>margin:
        return -1
    if a > b and difference>margin:
        return 1
    return 0
    pass

def close_compare(a, b, m=0):
    d = a-b
    if abs(d) <= m: return 0
    return d/abs(d)

def close_compare(a, b, margin = 0):

    compare = 0
    
    if margin != 0:
        if a < b and (b - a) <= margin:
            compare = 0
            return compare
        
        if a < b and (b - a) > margin:
            compare = -1
            return compare
        
        if a == b:
            compare = 0
            return compare
        
        if a > b and (a - b) <= margin:
            compare = 0
            return compare
        
        if a > b and (a - b) > margin:
            compare = 1
            return compare
        
    else:
        if a < b:
            compare = -1
            return compare
        if a > b:
            compare = 1
            return compare
        if a == b:
            compare = 0
            return compare

close_compare=lambda a,b,c=0:((a>b)-(b>a))*(abs(a-b)>c)

def close_compare(a, b, margin=0):
    dif=a-b

    if abs(dif) <= margin:
        return 0
    elif dif < 0:
        return -1
    else:
        return 1


def close_compare(a, b, margin=0):
    if margin ==None:
        margin=0
    else:
        if margin >=abs(a-b):
            return 0
        else:
            if a<b:
                return -1
            else:
                return 1
            


def close_compare(a, b, margin = 0):
    if abs(a - b) <= margin:
        return 0
    else:
        if a > b:
            return 1
        if a < b:
            return -1
        
        
    


def close_compare(a, b, margin=0):
    if abs(margin) > abs(a-b):
            return 0
    elif abs(margin) > abs(a-b):
            if a > b:
                return 1
            elif a < b:
                return -1
    elif abs(margin) == abs(a-b):
        return 0
    else:
        if a > b:
            return 1
        elif a < b:
            return -1
        else:
            return 0

def close_compare(a, b, margin=0):
    return 1 if a > b and (a-b) > margin else -1 if a < b and (b-a) > margin else 0

def close_compare(a, b, margin=0):
    
    closer = abs(b-a)
    
    if margin >= closer :
        
        return 0
    
    elif a>b :
        
        return 1 
    else:
        return -1

def close_compare(a, b, margin = 0):
    if a < b and a + margin < b: return -1
    if b < a and b + margin < a: return 1
    return 0

def close_compare(a, b, margin=0):
    return [-1, 1, 0][-(abs(a-b)<=margin) + (a>b+margin)]

def close_compare(a, b, margin=0):
    if margin >= ((a - b)**2)**0.5:
        return 0
    return (1 if a > b else -1)

def close_compare(a, b, margin=0):
    if a in range(b-margin, b+margin+1):
        return 0
    if a > b+margin:
        return 1
    if a < b+margin:
        return -1

def close_compare(a, b, margin=0):

    if(a < b):
        if(margin >= (b-a)):
            return 0
        else: return -1
    else: 
        if(margin >= (a-b)):
            return 0
        else: return 1


def close_compare(a, b, margin=0):
    if (a-b) >= 0 and (a-b)<= margin:
        return(0)
    elif (b-a) >= 0 and (b-a)<= margin:
        return(0)
    elif a < b:
        return(-1)
    else:
        return(1)

def close_compare(a, b, margin=0):
    if a < b:
        res = -1
    elif a > b:
        res = 1
    if margin >= abs(b - a):
        res = 0
    return res

def close_compare(a, b, margin=0):
    return 0 if a in range(b - margin, b + margin + 1) else -1 if a < b else 1

def close_compare(a, b, margin=0):
    if margin >= abs(a - b):
        return 0
    else:
        if a < b:
            return -1
        else:
            return 1

def close_compare(a, b, margin=0):
    d = abs(a - b)
    if d <= margin:
        return 0
    elif a < b:
        return -1
    return 1


def close_compare(a, b, margin=0):
    if a == b or abs(a - b) <= margin or abs(b - a) <= margin:
        return 0
    elif a > b:
        return 1
    else:
        return -1

def close_compare(a, b, margin = 0):
    area = range((b - margin), (b + 1 + margin))
    if a in area:
        return 0
    elif a < (b - margin):
        return -1
    elif a > (b + margin):
        return 1

def close_compare(a, b, margin=0):
    return -1 if b-margin>a else a-margin>b

def close_compare(a, b, margin=None):
    if not margin: return -1 if b>a else a>b
    return -1 if b-margin>a else a-margin>b

def close_compare(a=0, b=0, margin=0):
    return 0 if abs(a - b) <= margin else -1 if b > a else 1

def close_compare(a, b, margin=0):
    adiff = abs(a-b)
    if adiff <= margin:
        return 0
    alist = sorted([a, b])
    if alist[0] == a:
        return -1
    else:
        return 1



def close_compare(a, b, margin=0):
    if abs(a-b)<=abs(margin):
        return 0
    elif a<b:
        return -1
    else:
        return 1

def close_compare(a, b, margin=0):
    
    if margin<b-a:
        return -1
    if margin<a-b:
        return 1
    if margin>=abs(a-b):
        return 0


def close_compare(a, b, margin=0):
    if a-b>margin:
        return 1
    elif a+margin<b:
        return -1
    else:
        return 0

def close_compare(a, b, margin=0):
    if(a == b or (b - a <= margin and b - a >= 0) or (a - b <= margin and a - b >= 0)):
        return 0
    elif(a < b):
        return -1
    elif(a > b):
        return 1


def close_compare(a, b, margin = 0):
  if a >= b:
    res = a - margin
    if res <= b:
      return 0
    else:
      return 1

  if a <= b:
    ress = b - margin
    if ress <= a:
      return 0
    else:
      return -1

def close_compare(a, b, margin=0):
    if abs(a-b) <= margin: return 0
    return [-1,1][a>b]

def close_compare(a, b, margin = 0):
    c = abs(a-b)
    if c <= margin:
        return 0
    else:
        if a > b:
            return 1
        else:
            return -1
        
        
    pass

def close_compare(a, b, *args):
    if args:
        if abs(a-b)<=args[0]:
            return 0
    if a==b:
        return 0
    return -1 if a-b<0 else 1


def close_compare(a, b, margin=0):
    res = abs(a-b)
    
    if res <= margin:
        return 0
    else:
        if a < b:
            return -1
        elif a==b:
            return 0
        else:
            return 1

def close_compare(a, b, margin=0):
    if abs(b-a)<=abs(margin): return 0
    if a>b: return 1
    return -1


def close_compare(a, b, margin=0):
    if margin >= abs(a-b):
        return 0
    if a > b:
        return 1
    elif b > a:
        return -1


import math

def close_compare(a, b, margin=0):
    if(margin >= abs(a-b)):
        return 0
    elif(a < b):
        return -1
    else:
        return 1

def close_compare(a, b, margin=0):
    if margin==0:
        if a<b:
            return -1
        elif a>b:
            return 1
        else:
            return 0
    else:
        c=0
        c=a-b
        if c==0:
            return 0
        elif a>b and c<=margin:
            return 0
        elif a<b and abs(c)<=margin:
            return 0
        elif a>b and c>margin:
            return 1
        else:
            return -1

close_compare=lambda a,b,m=0:0 if abs(a-b)<=m else (a-b)//abs(a-b)

def close_compare(a, b, margin=0):
    if margin==0:
        if a>b:
            return 1
        elif b>a:
            return -1
        else:
            return 0
    else:
        if a>b and a-b>margin:
            return 1
        elif a<b and b-a>margin:
            return -1
        else:
            return 0


def close_compare(a, b, margin = 0):
    
    diff = abs(a-b)
    
    if margin >= diff:
        return 0
    elif a < b:
        return -1
    else: 
        return 1
    


def close_compare(a, b, margin=0):
    return -1 if a + margin < b else int(a - margin > b)

def close_compare(a, b, margin=0):
    return (abs(a - b) > margin) * (-1) ** (a < b)

def close_compare(a, b, margin = 0):
    if abs(a - b) > margin:
        return 1 if (a - b) > 0 else -1
    return 0

def close_compare(a, b, margin = 0):
    return 0 if abs(a-b) <= margin \
     else -1 if a < b \
     else 1 

def close_compare(a, b, margin=0):
    if margin >= abs(a - b):
        return 0
    if a > b:
        return 1
    else:
        return -1

def close_compare(a, b, margin=0):
    out = 0
    if a > b:
        out = 1
    else:
        out = -1
    if margin >= abs(a - b):
        out = 0
    return out


def close_compare(a, b, margin=0):

    if a == b:
        r = 0
    if a < b:
        r = -1
    if a > b:
        r = 1
    if abs(a-b) <= margin:
        r = 0
    
    return r