Complete the function that takes two numbers as input, ```num``` and ```nth``` and return the `nth` digit of `num` (counting from right to left).

## Note
- If ```num``` is negative, ignore its sign and treat it as a positive value
- If ```nth``` is not positive, return `-1`
- Keep in mind that `42 = 00042`. This means that ```findDigit(42, 5)``` would return `0`

## Examples

```
findDigit(5673, 4)     returns 5
findDigit(129, 2)      returns 2
findDigit(-2825, 3)    returns 8
findDigit(-456, 4)     returns 0
findDigit(0, 20)       returns 0
findDigit(65, 0)       returns -1
findDigit(24, -8)      returns -1
```

Difficulty: introductory

Starter code:

def find_digit(num, nth):
	

Solutions:
def find_digit(num, nth):
    if nth <= 0:
        return -1
    try:
        return int(str(num).lstrip('-')[-nth])
    except IndexError:
        return 0

def find_digit(num, nth):
    num = str(num)
    if nth<=0: return -1
    elif nth> len(num): return 0
    else:
        num = num[::-1]
        return int(num[nth-1])

def find_digit(num, nth):
    return 0 if nth>len(str(num)) else -1 if nth<=0 else int(str(num)[-nth])

def find_digit(num, n):
    num = str(abs(num))
    return -1 if n < 1 else 0 if n > len(num) else int(num[-n])

def find_digit(n, nth):
    if nth <= 0:
        return -1
    s = str(abs(n))
    return int(s[-nth]) if nth <= len(s) else 0

def find_digit(num, nth):
    if nth<=0:
        return -1
    if num<0: 
        num = -num
    return int((num/10 ** (nth-1))%10)

def find_digit(num, nth):
    try:
        return int(str(abs(num))[-nth]) if nth > 0 else -1
    except:
        return 0

def find_digit(num, nth):
    if nth < 1: return -1
    s = str(num)
    if nth > len(s): return 0
    return int(s[len(s) - nth])

def find_digit(num, nth):
    if nth <= 0:
        return -1

    num = abs(num)

    while num != 0 and nth > 1:
        num //= 10
        nth -= 1

    return num % 10


def find_digit(num, nth):
    return int(str(abs(num)).zfill(nth)[-nth]) if nth > 0 else -1

def find_digit(num, nth):
    num = str(num).replace('-','')[::-1]
    if nth <=0:
        return -1
    elif len(num) >= nth:
        return int(num[nth-1])
    else:
        return 0

def find_digit(num, nth):
    try:
        return -1 if nth<1 else int(str(abs(num))[::-1][nth-1])
    except:
        return 0

def find_digit(num, nth):
    try:
        return int(str(num)[-nth]) if nth > 0 else -1
    except:
        return 0

def find_digit(num, nth):
    if nth <= 0:
        return -1
    try:
        return int(str(num)[-nth])
    except IndexError:
        return 0

def find_digit(num, nth):
    str_num = str(num)
    if nth < 1:
        return -1
    if nth > len(str_num):
        return 0
    return int(str_num[::-1][nth - 1])

def find_digit(num, n):
    if n <= 0:
        return -1
    return abs(num) % 10**n // 10**(n-1)

def find_digit(num, nth):
    num = str(abs(num))
    return -1 if nth <= 0 else int(num[-nth]) if len(num) >= nth else 0

def find_digit(num, nth):
    if len(str(num)) < nth: return 0
    return int(str(num)[-nth]) if nth > 0 else -1 

def find_digit(num, nth):
    if nth <=0 :
      return -1
    if num <0 :
      num = abs(num)
    if nth>len(str(num)):
      return 0
    else :
      strin = str(num)
      return int(strin[len(strin)-nth])

def find_digit(num, nth):
    return abs(num) % 10**nth // 10**(nth-1) if nth > 0 else -1

find_digit=lambda n,d:-(d<1)or abs(n)//10**~-d%10

def find_digit(num, nth):
    return -1 if nth <= 0 else find_digit(-num, nth) if num < 0 else int(str(num).zfill(nth)[-nth])

def find_digit(num, nth):
    if nth <= 0:
        return -1
    return int(str(abs(num)).zfill(nth)[-nth])

def find_digit(num, nth):
    return int(f'{num:0{-~nth}}'[-nth]) if nth > 0 else -1

def find_digit(num, nth):
    return ~0 if nth <= 0 else (abs(num) // 10 ** (nth-1)) % 10

def find_digit(num, nth):
    #your code here
    num_str = str(num)
    if nth < 1:
        return -1
    elif nth > len(num_str):
        return 0
    else:
        return int(num_str[-1*nth])

def find_digit(num, nth):
    n = str(num)
    if len(n) < nth:
        return 0
    if nth <= 0:
        return -1
    return int(n.replace("-","0")[::-1][nth - 1])

def find_digit(num, n):
    if n <= 0: return -1
    num = str(abs(num))
    return len(num) >= n and int(num[-n])

def find_digit(num, nth):
    num = abs(num)
    num = str(num)
    num = num[::-1]
    
    if nth<1:
        return -1
    
    elif nth<=len(num):
        return int(num[nth-1])

    else:
        return 0

def find_digit(num, nth):
    if nth <= 0: return -1
    n = str(abs(num))
    return int(n[-nth]) if nth <= len(n) else 0

def find_digit(num, nth):
    try:
        if nth>0:
            return int(list(str(num))[-nth])
        else:
            return -1
    except:
        return 0

def find_digit(num, nth):
    if nth > 0:
        try:
            return int(list(str(num)[::-1])[nth-1])
        except IndexError:
            return 0
    else:
        return -1

def find_digit(num, nth):
    num = str(num)
    if nth < 1: return -1
    if nth > len(num): return 0
    i = [char for char in num]
    return int(i[-nth])

def find_digit(num, nth):
    if nth>len(str(num).replace('-','')) and nth>0:
        return 0
    elif nth<=0:
        return -1
    else:
        return int(str(num).replace('-','')[-nth])

def find_digit(num, nth):
    if nth <= 0 :
        return -1
    
    string = str(num).replace('-','')
    
    if nth > len(string):
        return 0
    
    return int(string[-1*nth])

def find_digit(num, nth):
    s = str(num)
    if nth in range(1, len(s) + 1):
        return int(s[-nth])
    if nth == 0 or nth <= 0:
        return -1
    else:
        return 0


def find_digit(num, nth):
    
    if nth<=0:
        
        return -1
    
    n = abs(num)
    
    d = [int(x) for x in str(n)]
    
    l = len(d)
    
    if nth>l:
        
        return 0
    
    else:
    
        p = d[::-1]
    
        for i,j in enumerate(p,1):
        
            if i==nth:
            
                return j


def find_digit(num, nth):
    if nth < 1:
        return -1
    
    num = str(abs(num))
    if nth > len(num):
        return 0
    calc = len(num) - nth
    return int(num[calc])


def find_digit(num, nth):
    try:
        if nth>0:
            return int(str(num)[-nth])
        return -1
    except:
        return 0

def find_digit(num, nth):
    
    if nth <= 0:
        return -1 
    else: 
        num = str(num)
        num_digits = ""

        for x in num:
            if x != "-":
                num_digits += x

        if len(num_digits) < nth:
            return 0
        else:
            nth = nth * -1
            result = num[nth]
            return int(result)

def find_digit(num, nth):
    num = str(abs(num))
    return -1 if nth <= 0 else int(num.zfill(nth)[-nth])


def find_digit(num, nth):
    if nth <= 0:
        return -1
    elif nth <= len(str(num)):
        num = str(num)
        number = num[-nth]
        return int(number)
    else:
        return 0

def find_digit(num, nth):
    print(num, nth)
    if nth <= 0: return -1
    s = str(abs(num))
    if nth > len(s): return 0
    return int(s[-nth])

def find_digit(num, nth):
    if nth <= 0:
        return -1
    else:
        num = str(abs(num))
        num = num.zfill(nth)
        num = num[::-1]
        return int(num[nth-1])

def find_digit(num, nth):
    if nth < 1: return -1
    n = [int(x) for x in str(abs(num))]
    return 0 if len(n) < nth else n[len(n) - nth]

def find_digit(num, nth):
    if nth <= 0:
        return -1
    elif nth > abs(num) or nth > len(str(abs(num))):
        return 0
    else:
        return int(str(abs(num))[-nth])

def find_digit(num, nth):
    if nth <= 0:
        return -1
    x = abs(num)
    for i in range(1, nth):
        x //=  10
    return x % 10

def find_digit(num, nth):
    if nth <= 0:
        return -1
    elif len(str(num)) < nth:
        return 0
    return int(str(num)[::-1][nth-1])


def find_digit(num, nth):
    m= str(abs(num))
    if nth <= 0:
        return -1
    elif num !=0 and len(m) >= nth:        
        return int(m[-nth])
    else:
        return 0

def find_digit(num, nth):
    if nth > len(str(num).replace("-", "")):
        return 0
    if nth <= 0:
        return -1
    else:
        return int(str(num)[::-1][nth-1])


def find_digit(n, m):
    return int(f"{n:099d}"[::-1][m-1]) if m>0 else -1

def find_digit(num, nth):
    n = str(abs(num))[::-1]
    return -1 if nth < 1 else 0 if nth > len(n) else int(n[nth-1])

def find_digit(num, nth):
    if nth < 1:
        return -1
    if num < 0:
        num *= -1
    num = str(num)
    if nth > len(num):
        return 0
    return int(num[len(num) - nth])

def find_digit(num, nth):
    print(num)
    num=abs(num)
    if nth > len(str(num)):
        return 0
    if nth <= 0:
        return -1
    if nth <= len(str(num)):
        num= str(num)
        return int(num[-nth])

def find_digit(num, nth):
    if nth<=0:
        return -1
    num_mod=str(abs(num))[::-1]
    if nth>len(num_mod):
        return 0
    else:
        return int(num_mod[nth-1])


def find_digit(n, i):
    return (abs(n)//10**(i-1))%10 if i > 0 else -1

def find_digit(num, nth):
    if nth <= 0:
        return -1
    
    if num < 0:
        num = num * -1
        
    if len(str(num)) < nth:
        return 0
    
    return int(str(num)[::-1][nth-1])


def find_digit(num, nth):
    num = str(num)
    try:
        if nth <= 0 :
            return -1
        else:
            return int(num[-nth])
    except IndexError:
        return 0

def find_digit(num,n):
    return int(str(abs(num)).zfill(n+1)[-n]) if n>0 else -1

def find_digit(num, nth):
    snum=str(num)
    if nth<=0:
        return -1
    try:
        if snum[(-nth)].isnumeric:
            return int(snum[(-nth)])
    except:
        return 0

def find_digit(num, nth):
    nList = []
    num = str(num)
    for i in num:
        nList.append(i)
    
    if nth <= 0:
        return -1
    elif nth > len(nList):
        return 0
    
    for index,curr in enumerate(nList):
        if index == len(nList) - nth:
            return int(curr)


def find_digit(num, nth):
    #your code here
    strnum = str(num)
    if nth <= 0:
        return -1
    elif nth > len(strnum):
        return 0
    else:
        return int(strnum[len(strnum)-nth])

def find_digit(num, nth):
    if int(nth) <= 0:
        return -1
    elif int(num) < 0:
        num = int(num) * -1
    return int(num) // 10**(nth-1) % 10


def find_digit(num, nth):
    if nth<=0 : return -1
    s=str(num).strip("-")
    if len(s)<nth : return 0
    return int(s[-nth])

def find_digit(num, nth):
    try:
        if nth > 0:
            return int(str(abs(num))[::-1][nth - 1])
        return -1
    except:
        return 0

def find_digit(num, nth):
      
    num1 = abs(num)
    
    res = [int(x) for x in str(num1)]
    nnum = len(res)
    if nth <= 0:
        return (-1)
    if nth > nnum:
        return (0)
    else:    
        return (res[-nth])



def find_digit(num, nth):
    if nth<=0:
        return -1
    
    else:
        num=abs(num)
        if nth>len(str(num)):
            return 0
        else:
            return int(str(num)[len(str(num))-nth])

def find_digit(num, nth):
    
    try :
        return -1 if nth < 1 else int(str(num)[-nth])
    except :
        return 0

def find_digit(num, nth):
    if nth<0:
        return -1
    elif nth == 0:
        return -1
    try:
        
        k = nth
        i = str(num)
        final = i[-k]
        m = int(final)
        return m
    
    except:
        
        return 0

def find_digit(n1, n2):
    try:
        if n2 < 0 or n2 == 0:
            return -1
        n3 = str(abs(n1))
        n4 = int('-' + str(n2))
        return int(n3[n4])
    except IndexError:
        return 0


def find_digit(num: int, nth: int) -> int:
    if nth < 1:
        return -1
    try:
        return int(str(abs(num))[-nth])
    except IndexError:
        return 0



def find_digit(num, nth):
    
    numStr = str(abs(num))
          
    if nth > len(numStr):
        return 0
                 
    elif nth <= 0:
        return -1
                 
    return int(numStr[len(numStr) - nth])

def find_digit(num, nth):
    # if nth is <= 0
    if nth <= 0:
        # return -1
        return -1
    # convert the num to a string
    num = str(num)
    # find the index moving right to left
    index = len(num) - nth
    if index >= 0:
        # return number at that index
        return int(num[index])
    else:
        return 0

def find_digit(num, nth):
    if nth < 1:
        return -1
    else:
        try:
            number = int(str(num)[-nth])
        except:
            number = 0
        return number


def find_digit(num, nth):
    return int((f'{abs(num):0{nth}}'[::-1])[nth-1]) if nth > 0 else -1

def find_digit(num, nth):
    if nth <= 0: return -1
    num = str(abs(num))
    return 0 if nth > len(num) else int(num[::-1][nth-1])


def find_digit(num, nth):
    print((num, nth))
    num = str(abs(num))[::-1]
    
    if nth <= 0:
        return -1
    if nth > len(num):
        return 0
    else:
        return int(num[nth-1])
    


def find_digit(num, nth):
    if (nth <= 0):
        return -1
    num = abs(num)
    a = []
    while(num!=0):
        a.append(num%(10))
        num = num//10
    if nth >len(a):
        return 0
    else:
        return a[nth-1]

def find_digit(num, nth):
    if nth <= 0:
        return -1
    elif len(str(num)) < nth:
        return 0
    else:
        num = abs(num)
        num = [int(d) for d in str(num)]
        return num[-nth]


def find_digit(num, nth):
    if nth<1: return -1
    num = abs(num)
    d = nth - 1
    return (num//pow(10,d))%10

def find_digit(num, nth):
    if nth <= 0: return -1
    else: return int((str(abs(num))[::-1] + '0'*nth)[nth-1])


def find_digit(num, nth):
    if nth > 0 :
        return int(str(abs(num))[::-1].ljust(nth, '0')[nth-1]) 
    else:
        return -1


def find_digit(num, nth):
    string = str(abs(num)).zfill(nth)
    return int(string[-1*nth]) if nth > 0 else -1

def find_digit(num, nth):
    if nth <= 0:
        return -1
        
    s = str(abs(num))[::-1]
    if nth > len(s):
        return 0
        
    return int(s[nth-1])

def find_digit(num, nth):
    if nth <= 0:
        return -1
    elif nth <= len(str(num)):
        return int(str(num)[::-1][nth-1])
    else:
        return 0

def find_digit(BLM, BlM):
    if BlM <= 0: return -1
    return 0 if BlM > len(str(BLM)) else int(str(BLM)[::-1][BlM-1])

def find_digit(num, nth):
    if nth<1:
        return -1
    num = str(abs(num))
    if nth > len(num):
        return 0
    print(num,nth)
    return int(num[len(num)-nth])

def find_digit(n, i):
    if i < 1: return -1
    try: return int(str(abs(n)).zfill(i)[-i])
    except: return -1

def find_digit(num, nth):
    if nth <= 0:
        return -1
    return int([*reversed(str(num))][nth-1]) if nth < len(str(num)) + 1  else 0

def find_digit(num, nth):
    if nth > len(str(num)):
      return 0
    elif nth <= 0:
      return -1
    return int(str(num)[-nth])

def find_digit(num, nth):
    if nth <= 0:
        return -1
        
    number = str(abs(num))
    
    if nth > len(number):
        return 0
    else:
        return int(number[-nth])


def find_digit(num, nth):
    num = abs(num)
    return -1 if nth < 1 else 0 if len(str(num)) < nth else int(str(num)[len(str(num)) - nth])

def find_digit(num, nth):
    num = str(abs(num))[::-1]
    if nth <= len(num) and nth > 0: 
        return int(num[nth-1])
    elif nth >= len(num): 
        return 0 
    else: 
        return -1

def find_digit(num,nth):
    if nth <= 0:
        return -1
    else:
        num = str(abs(num))
        if nth > len(num):
            return 0
        else:
            return int(num[-nth])


def find_digit(num, nth):
  y = list(str(num))
  if nth > len(y):
      return 0
  if nth <= 0 :
     return -1
  else:
    return int(str(num) [-nth])


def find_digit(num, nth):
    #your code here
    if nth>len(str(abs(num))) : return 0
    if nth>0 : return int(str(abs(num))[::-1][nth-1])
    else : return -1

def find_digit(num, nth):
    if nth <= 0:
        return -1;
    else:
        num = abs(num)
        while nth > 0:
            mod = int(num % 10)
            num /= 10
            nth -= 1
        return mod

import unittest


def find_digit(num, nth):
    num = abs(num)
    if nth <= 0:
        return -1
    if len(str(num)) < nth:
        return 0
    return int(str(num)[::-1][nth-1])
    
    
class TestFindDigit(unittest.TestCase):
    def test_should_return_negative_one_given_nth_is_negative(self):
        negative_nth = -123
        self.assertEqual(find_digit(num=-12345, nth=negative_nth), -1)

    def test_should_return_negative_one_given_nth_is_zero(self):
        zero = 0
        self.assertEqual(find_digit(num=-12345, nth=zero), -1)

    def test_should_return_0_given_nth_is_greater_than_length_of_num(self):
        self.assertEqual(find_digit(num=0, nth=20), 0)

    def test_should_return_0_given_nth_is_greater_than_length_of_num_with_negative_sign(self):
        self.assertEqual(find_digit(num=-456, nth=4), 0)

    def test_should_return_4_when_given_num_is_5673(self):
        self.assertEqual(find_digit(num=5673, nth=4), 5)


def find_digit(num, nth):
    #your code here
    if nth>len(str(abs(num))):
        return 0
    elif nth>0 and abs(num)>=nth:
        y = str(abs(num))
        return int(y[-nth])
    return -1