您好,我正在开发一个简单的游戏。我希望在提升等级之前先获得100点经验值,然后将这些点重置。例如,一个人获得12分(目前为99分),它应该达到2级和11分。它也应该说明他们是否获得244分,然后分别给出2级和44分。我当前的代码
points = points_sale
def bonus(price):
if 0 == int(price):
bonus = 0
return bonus
if 1 <= int(price) <= 100:
bonus = 1
return bonus
if 101 <= int(price) <= 250:
bonus = 2
return bonus
if 251 <= int(price) <= 500:
bonus = 5
return bonus
if 501 <= int(price) <= 1000:
bonus = 10
return bonus
if 1001 <= int(price) <= 5000:
bonus = 25
return bonus
if 5001 <= int(price):
bonus = 50
return bonus
adjusted = bonus(price=price)
newpoints = int((currentPoints + points + adjusted)*quantity)
if newpoints > 100:
<insert code here>
如果经验值超过100,如何获得经验值并重置+1。
最佳答案
您可以使用divmod
进行除法并同时获得余数:
newpoints = 244
levels_up, exp_leftover = divmod(newpoints, 100)
print(levels_up, exp_leftover) # >> (2, 44)