如何简单地根据输入经验计算等级?
我正在为一款名为runescape的游戏制作“宠物机会生成器”。该程序会询问您当前的经验,并根据用户输入的经验值来估算等级。下面是我可以想到的唯一方法,但是正如您所看到的,有一堵文字墙基本上可以复制粘贴40次。请帮忙!

我目前有:

def calculate_level(xp):
if xp < 368599:
    level = 62
elif xp < 368599 * 1.101141**2:
    level = 63
elif xp < 368599 * 1.101141**3:
    level = 64
elif xp < 368599 * 1.101141**4:
    level = 65
elif xp < 368599 * 1.101141**5:
    level = 66
elif xp < 368599 * 1.101141**6:
    level = 67
elif xp < 368599 * 1.101141**7:
    level = 68
elif xp < 368599 * 1.101141**8:
    level = 69
elif xp < 368599 * 1.101141**9:
    level = 70
elif xp < 368599 * 1.101141**10:
    level = 71
elif xp < 368599 * 1.101141**11:
    level = 72
elif xp < 368599 * 1.101141**12:
    level = 73
elif xp < 368599 * 1.101141**13:
    level = 74
elif xp < 368599 * 1.101141**14:
    level = 75
elif xp < 368599 * 1.101141**15:
    level = 76
elif xp < 368599 * 1.101141**16:
    level = 77
elif xp < 368599 * 1.101141**17:
    level = 78
elif xp < 368599 * 1.101141**18:
    level = 79
elif xp < 368599 * 1.101141**19:
    level = 80
elif xp < 368599 * 1.101141**20:
    level = 81
elif xp < 368599 * 1.101141**21:
    level = 82
elif xp < 368599 * 1.101141**22:
    level = 83
elif xp < 368599 * 1.101141**23:
    level = 84
elif xp < 368599 * 1.101141**24:
    level = 85
elif xp < 368599 * 1.101141**25:
    level = 86
elif xp < 368599 * 1.101141**26:
    level = 87
elif xp < 368599 * 1.101141**27:
    level = 88
elif xp < 368599 * 1.101141**28:
    level = 89
elif xp < 368599 * 1.101141**29:
    level = 90
elif xp < 368599 * 1.101141**30:
    level = 91
elif xp < 368599 * 1.101141**31:
    level = 92
elif xp < 368599 * 1.101141**32:
    level = 93
elif xp < 368599 * 1.101141**33:
    level = 94
elif xp < 368599 * 1.101141**34:
    level = 95
elif xp < 368599 * 1.101141**35:
    level = 96
elif xp < 368599 * 1.101141**36:
    level = 97
elif xp < 368599 * 1.101141**37:
    level = 98
else:
    level = 99
return level

最佳答案

闻起来像对数

import math

def xp_to_level(xp):
    return math.ceil(math.log(xp/368599, 1.101141)) + 61


用法:

>>> xp_to_level(123456)
50

关于python - 如何根据经验确定水平?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47683257/

10-12 18:11