Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
简单游戏的Python体验和关卡积分_Python_Python 3.x - Fatal编程技术网

简单游戏的Python体验和关卡积分

简单游戏的Python体验和关卡积分,python,python-3.x,Python,Python 3.x,你好,我正在开发一个简单的游戏。我希望在等级提升之前有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:

你好,我正在开发一个简单的游戏。我希望在等级提升之前有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>
points=points\u销售
def奖金(价格):
如果0==int(价格):
奖金=0
回报奖金

如果1您可以使用
divmod
进行除法,同时获得余数:

newpoints = 244

levels_up, exp_leftover = divmod(newpoints, 100)

print(levels_up, exp_leftover) # >> (2, 44)

那么,你的问题是什么?你能说得更清楚一点吗?使用模运算符,例如
newpoints=newpoints%100
或速记
newpoints%=100
。您还可以使用整数除法获取级别,例如
级别=newpoints//100
(在上述操作之前)。这在
python
中非常常见,它有一个函数来组合这一点:
levels,newpoints=divmod(newpoints,100)
这是简单而有效的。