In this Kata you are a game developer and have programmed the #1 MMORPG(Massively Multiplayer Online Role Playing Game) worldwide!!! Many suggestions came across you to make the game better, one of which you are interested in and will start working on at once.

Players in the game have levels from 1 to 170, XP(short for experience) is required to increase the player's level and is obtained by doing all sorts of things in the game, a new player starts at level 1 with 0 XP. You want to add a feature that would enable the player to input a target level and the output would be how much XP the player must obtain in order for him/her to reach the target level...simple huh.

Create a function called ```xp_to_target_lvl``` that takes 2 arguments(```current_xp``` and ```target_lvl```, both as integer) and returns the remaining XP for the player to reach the ```target_lvl``` formatted as a rounded down integer.

Leveling up from level 1 to level 2 requires 314 XP, at first each level up requires 25% XP more than the previous level up, every 10 levels the percentage increase reduces by 1. See the examples for a better understanding.

Keep in mind that when players reach level 170 they stop leveling up but they continue gaining experience.

If one or both of the arguments are invalid(not given,  not in correct format, not in range...etc) return "Input is invalid.".

If the player has already reached the ```target_lvl``` return ```"You have already reached level target_lvl."```.

Examples:
```
xp_to_target_lvl(0,5) => XP from lvl1 to lvl2 = 314
                         XP from lvl2 to lvl3 = 314 + (314*0.25) = 392
                         XP from lvl3 to lvl4 = 392 + (392*0.25) = 490
                         XP from lvl4 to lvl5 = 490 + (490*0.25) = 612
                         XP from lvl1 to target_lvl = 314 + 392 + 490 + 612 = 1808
                         XP from current_xp to target_lvl = 1808 - 0 = 1808

xp_to_target_lvl(12345,17) => XP from lvl1 to lvl2 = 314                   
                               XP from lvl2 to lvl3 = 314 + (314*0.25) = 392
                               XP from lvl3 to lvl4 = 392 + (392*0.25) = 490
                               ...
                               XP from lvl9 to lvl10 = 1493 + (1493*0.25) = 1866 
                               XP from lvl10 to lvl11 = 1866 + (1866*0.24) = 2313 << percentage increase is 
                               ...                                                   reduced by 1 (25 - 1 = 24)
                               XP from lvl16 to lvl17 = 6779 + (6779*0.24) = 8405
                               XP from lvl1 to target_lvl = 314 + 392 + 490 + 612 + ... + 8405 = 41880
                               XP from current_xp to target_lvl = 41880 - 12345 = 29535

xp_to_target_lvl() => "Input is invalid."             }
xp_to_target_lvl(-31428.7,'47') => "Input is invalid." }> Invalid input
xp_to_target_lvl(83749,0) => "Input is invalid."   }

xp_to_target_lvl(2017,4) => "You have already reached level 4."
xp_to_target_lvl(0,1) => 'You have already reached level 1.'
```

Make sure you round down the XP required for each level up, rounding up will result in the output being slightly wrong.

Difficulty: introductory

Starter code:

def xp_to_target_lvl(current_xp=None, target_lvl=None):
	

Solutions:
def xp_to_target_lvl(*args):
    if len(args) < 2:
        return 'Input is invalid.'
        
    current_xp, target_lvl = args
    
    if not isinstance(target_lvl, int):
        return 'Input is invalid.'
    
    if not (0 < target_lvl < 171):
        return 'Input is invalid.'
    
    if current_xp < 0:
        return 'Input is invalid.'
        
    level = 1
    xp = 314
    xp_bump = 25
    
    sum_ = 0
    while level < target_lvl:
        sum_ += xp
        level += 1
        xp_bump_reduction = level // 10
        xp += int(xp * (xp_bump - xp_bump_reduction) / 100)
        
    diff = sum_ - current_xp
    if diff <= 0:
        return 'You have already reached level {}.'.format(target_lvl)
    else:
        return diff


def xp_to_target_lvl(current_xp=None, target_lvl=None):
    
    invalid = "Input is invalid."
    if (type(target_lvl) is not int) or (type(current_xp) is not int):
        return invalid
    if current_xp < 0 or target_lvl < 1 or target_lvl > 170:
        return invalid
    if target_lvl == 1:
        return "You have already reached level 1."
    
    needed_xp = 314
    if target_lvl > 2:
        needed_xp = calc_needed(target_lvl)
    
    if current_xp >= needed_xp:
        return "You have already reached level %s." % target_lvl
    
    return needed_xp - current_xp
        
def calc_needed(target_lvl):
    increase = 25
    lvl_xp = needed_xp = 314
    
    for lvl in range(3, target_lvl+1):
        lvl_xp += int( lvl_xp * increase / 100 )
        needed_xp += lvl_xp
        if lvl % 10 == 0:
            increase -= 1
        
    return needed_xp
    


from fractions import Fraction

def xp_to_target_lvl(current_xp=None, target_lvl=None):
    if not isinstance(current_xp, int) or not isinstance(target_lvl, int) or current_xp < 0 or not 1 <= target_lvl <= 170:
        return "Input is invalid."
    increase, xp, total = Fraction(5, 4), 314, 0
    for i in range(2, target_lvl+1):
        if not i%10: increase -= Fraction(1, 100)
        total, xp = total+xp, int(xp*increase)
    return total - current_xp if total > current_xp else f"You have already reached level {target_lvl}."

from itertools import accumulate

XPS = [0, 0, 314]
percent = 125
for i in range(3, 170 + 1):
    XPS.append(XPS[-1] * percent // 100)
    if i % 10 == 0:
        percent -= 1
XPS = list(accumulate(XPS))

def xp_to_target_lvl(current_xp=None, target_lvl=None):
    if not (
        isinstance(current_xp, int)
        and isinstance(target_lvl, int)
        and current_xp >= 0
        and 1 <= target_lvl <= 170
    ):
        return "Input is invalid."
    required = XPS[target_lvl] - current_xp
    return required if required > 0 else f"You have already reached level {target_lvl}."


from itertools import accumulate

XP=[0,0,314]
for i in range(2,170):
    XP.append(XP[-1]*(125-i//10)//100)
XP=list(accumulate(XP))

def xp_to_target_lvl(xp=-1, lvl=0):
    try: 
        if xp<0 or lvl<1: return 'Input is invalid.'
        res = XP[lvl]-xp
        return res if res>0 else f'You have already reached level {lvl}.'
    except: return 'Input is invalid.'

def xp_to_target_lvl(current_xp='', target_lvl=''):
    # good luck ^_^
    if isinstance(current_xp,int) and isinstance(target_lvl,int):
        if current_xp>=0 and 1<=target_lvl<=170:
            a=[314]
            for i in range(2,target_lvl+2):
                a.append(int(a[-1]*(1.25-0.01*(i//10))))
            return sum(a[:target_lvl-1])-current_xp if sum(a[:target_lvl-1])-current_xp>0 else 'You have already reached level {}.'.format(target_lvl)
    return 'Input is invalid.'


from math import floor


def xp_to_target_lvl(current_xp=-100, target_lvl=-100):
    if type(current_xp) != int or type(target_lvl) != int or current_xp + target_lvl <= 0 or target_lvl > 170 or target_lvl < 1:
        return "Input is invalid."

    exp_req = 314
    inc = 25
    level = 1
    exp = 0
    while level < target_lvl:
        level += 1
        if level % 10 == 0:
            inc -= 1
        exp += exp_req
        exp_req = floor(exp_req + exp_req * inc / 100)

    if exp - current_xp <= 0:
        return f"You have already reached level {target_lvl}."
    return exp - current_xp

a,e,t,m = [0,314],314,314,.25
for i in range(2,170):
    x = int(e*(1+m))
    t += x
    a.append(t)
    e = x
    if not (i+1)%10:
        m -= .01
a[-1] = 769832696988485

def xp_to_target_lvl(e=None,lvl=None):
    try:        
        if e<0 or lvl<1: return 'Input is invalid.'
        if lvl==1 or e >= a[max(lvl-1,0)]: return f'You have already reached level {lvl}.'
        return a[lvl-1] - e
    except:
        return 'Input is invalid.'

from math import floor

def xp_to_target_lvl(*args):
    if len(args) != 2:
        return "Input is invalid."
    
    current_xp = args[0]
    target_lvl = args[1]
    if type(current_xp) is not int or type(target_lvl) is not int or current_xp < 0 or target_lvl <= 0 or target_lvl > 170:
        return "Input is invalid."
    
    req_xp = 0
    xp_lvl = 314
    for i in range(1,target_lvl):
        print(xp_lvl)
        req_xp += xp_lvl
        xp_lvl *= (1.25 - 0.01*((i+1)//10))
        xp_lvl = floor(xp_lvl)
    
    print(f"\n{req_xp}")
    
    return req_xp - current_xp if req_xp > current_xp else f"You have already reached level {target_lvl}."

def xp_to_target_lvl(cur_xp = -1, lvl = -1):
    if not isinstance(cur_xp, int) or cur_xp < 0 or not isinstance(lvl, int) or lvl <= 0 or lvl > 170: 
        return "Input is invalid."
    
    count = 1
    xp = 0
    multipler = 25
    next_lvl = 314
    
    while count < lvl:
        count += 1
        if count == lvl: xp += next_lvl; print(xp, count); break
        if count % 10 == 0: multipler = float(multipler - 1)
        xp += next_lvl
        next_lvl = next_lvl + int(next_lvl * (multipler / 100))
        print(xp, count, multipler)
        
    result = xp - cur_xp
    if result > 0:
        return result
    else:
        return f'You have already reached level {lvl}.'