Note that there are some explanatory texts on larger screens.

plurals
  1. POrandint() error 'empty range for randrange' in the python random module
    primarykey
    data
    text
    <p>when I use randint() sometimes this error will appear:</p> <pre><code>ValueError: empty range for randrange() (1,1, 0) </code></pre> <p>why is this/how do i stop it from happening?</p> <p>im not doing anything wrong as far as i can tell, this error dosnt apppear on any specific randit() call and only appears every now and then.</p> <p>the error takes me to the actual random module:</p> <pre><code>raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width) </code></pre> <p>Here is my whole program (i call randint() often)</p> <pre><code> from random import randint units = 5 food = 20 days_without_food = 0 SP = 4 print '------------------------------------------------------' print 'welcome! starting a new game' print '------------------------------------------------------' location = 'plains' def search(): #do2 create leadership skill or search skill global units global food global SP if SP &gt; 0: SP = SP - 1 found = randint(1,3) if found == 1 or found == 2: if units == 0: units = randint(1,5) print '------------------------------------------------------' print 'you recruited %s units!' %units main() a = units / 2 ammount = randint(1,a) units = units + ammount print '------------------------------------------------------' print 'you recruted %s units!' %ammount #recruit a random ammount of units not over half ammount of already owned. main() else: print '------------------------------------------------------' print 'you did not find anything' main() else: print '------------------------------------------------------' print 'your army is too tired to look for anything' main() def battle(): #do1 create villages with a random amount of units between 100-300 global SP global units global food if SP == 0: print '------------------------------------------------------' print 'your army is too tired to fight' main() else: SP = SP -1 if units == 0: print '------------------------------------------------------' print 'it is madness to go looking for a fight without an army' main() a = units / 2 b = units * 2 e_units = randint(a,b) e_units = int(e_units) #random ammount of enemy units reletave to ammount of player units if e_units == 0: e_units = randint(1,3) guess = randint(e_units-5,e_units+5) if guess &lt; 0: guess = randint(1,e_units+10) print '------------------------------------------------------' print 'it looks like the enemy has %s units' %guess #unacurate guess of how many enemy units there are print 'a: attack' print 'b: leave' action = raw_input('a or b?') if action == 'a': units = units - e_units if units &lt;0: units = 0 print '------------------------------------------------------' print 'you lost the battle and all of your units' main() else: a = e_units * 2 ammount = randint(1,a) food = food + ammount print '------------------------------------------------------' print 'you won the battle and found %s food!' %ammount + ' after the battle you have %s units' %units main() # battle else: chance = randint(1,10) if chance == 10: units = units - e_units if units &lt;0: units = 0 #attempt to leve print '------------------------------------------------------' print 'it is to late, they spotted you!' + ' after the battle you have %s units' %units main() else: print '------------------------------------------------------' print 'you leave without the enemy spotting you' main() def change_location(): global food global units global SP global days_without_food if food &lt; 0: days_without_food = days_without_food + 1 if days_without_food &gt; 0 and days_without_food &lt; 3: chance = randint (1,5) if not chance == 5: print '------------------------------------------------------' print 'you have no food, but your men are stll loyal to you' food = 0 main() elif chance == 5: deserters = randint(1,int(units/4)) units = units - deserters print '------------------------------------------------------' print 'without any food, %d men deserted your army' % deserters food = 0 main() else: chance = randint(1,2) if chance == 1: men_starved = randint(1,int(units/4)) units = units - men_starved print '------------------------------------------------------' print 'without any food, %d units starved to death' % men_starved food = 0 main() else: deserters = randint(1,int(units/4)) units = units - deserters print '------------------------------------------------------' print 'without any food, %d men deserted your army' % deserters food = 0 main() days_without_food = 0 SP = 3 food = food - int(units / 2) places = ['plains','beach','river','mountain','sea','desert','hills', 'forest','volcano','jungle','storm','village'] #do3 add more places location = places[randint(0,len(places)-1)] main() def main(): #do1 Create nomadic and settled versions global units global location global food global SP print '------------------------------------------------------' print 'you are at a %s' %location print 'a:look for a fight' print 'b:look for supplies' print 'c:Take stock' print 'd:Move on' action = raw_input('a,b,c, or d?') if action == 'a': battle() elif action == 'b': search() elif action == 'c': print '------------------------------------------------------' print 'food: %s. ' %food + ' units: %s. ' %units + ' Search points %s. ' %SP main() elif action == 'd': change_location() else: main() main() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload