tags:

views:

32

answers:

2

Simple problem: precentage_chance = 0.36

if <don't know what>:
   #action here has 36% chance to execute
   pass

How can i solve this problem?

+2  A: 

You could use random.random:

>>> import random
>>> if random.random() < percentage_chance:
    print('aaa')
SilentGhost
Great, now i have random.randrange(1,100) in range(1,int(chance*100)) but i don't think is this right.
methyl
@methyl: what's wrong with my solution?
SilentGhost
Its much better than my :)
methyl
A: 
import random
if random.randint(0,100) < 36:
    do_stuff()
Blue Peppers
it is better to use `randrange` function.
SilentGhost