I'm making a game and I would like make my char's damage range(4,7),
To inflict damage, im doing enemyhp - chardamage, How would I make chardamage a random number from the range(4,7)?
You can do this using random.randrange:
random.randrange(4, 8)
You need to use 8 because in Python, the range is inclusive of the lower bound and exclusive of the upper bound.
You need range(4,8) because the upper bound is always -1. range(4,7) will give you 4,5,6
from random import choice
choice(range(4,8))
xrange there (for Python 2 users), and gives the right results :)import random
damage = random.randint(4, 7) # To get random num from {4,5,6,7}
randint() behaves differently from randrange(), and you would need to use randint(4, 7) to get a random integer from {4, 5, 6, 7}.
random.randintin the first result.range(4, 7)(==[4, 5, 6]), or did you mean[4, 5, 6, 7]?