Simple problem:
percentage_chance = 0.36 if some_function(percentage_chance): # action here has 36% chance to execute pass
How can I write some_function
, or an expression involving percentage_chance
, in order to solve this problem?
You could use random.random
:
import random if random.random() < percentage_chance: print('aaa')
import random if random.randint(0,100) < 36: do_stuff()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With