Convert exp to levels

Don’t wanna make a bunch of posts for each game, so I’ll just add the required variables here. If you want to see an example, I have one for treasure wars and one for skywars. (note: exclude the if statement if there is no level xp cap)

if xp >= [xp for max level]:
        exactlevel = (xp-{xp for max level})/{highest increment} + {level xp cap}
        xps = [0, {increment increase between levels}]
        x = {increment increase between levels}
        y = {increment increase between levels}
        for i in range(50):
            x = x+{increment increase between levels}
            y = int(x + y)
            i += 1
        for i in range(len(xps)):
            if xp > xps[i]:
                exactlevel = i + float(xp - xps[i-1]) / (xps[i] - xps[i-1])

Hope this helps!