Python experience and level points for a simple game

275
July 20, 2017, at 07:40 AM

Hello I am developing a simple game. I want there to be 100 experience points before an increase in level, and the points reset. Example, a person gets 12 points(there current is 99), it should go to level 2 and 11 exp points. It should also account for if they get 244 points, then 2 levels and 44 points should be given respectively. My current code

``````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
newpoints = int((currentPoints + points + adjusted)*quantity)
if newpoints > 100:
<insert code here>
``````

How do i get the experience points to reset if they are above 100 and add a +1 to level.

You can can use `divmod` to divide and get the remainder at the same time:

``````newpoints = 244
levels_up, exp_leftover = divmod(newpoints, 100)
print(levels_up, exp_leftover) # >> (2, 44)
``````
POPULAR ONLINE

Do not trigger my method more than once

In the moment, sign() method returns a Boolean argument, but it can't be triggered more than onceHence, I can't use that method in my view with if contract

192

Scrapy Program stops after about 500-600 items

I hired someone off of freelancer to make this spider for ebayI am just learning python and needed it quick so that was our solution

173

Python class instance evaluates to false?

In the following example:

334

Do focus events work for QDockWidget objects?

I'm having trouble getting the "focusInEvent" to work for a QDockWidget-derived class in PyQt4I've hunted around and it seems that my reimplementation syntax of the event is correct, but my code in the event handler never gets executed (I set a breakpoint...

212