采取行动的机会百分比 [英] Percentage chance to make action
本文介绍了采取行动的机会百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单的问题:
percentage_chance = 0.36
if some_function(percentage_chance):
# action here has 36% chance to execute
pass
我如何编写some_function
,或者一个涉及percentage_chance
的表达式来解决这个问题?
How can I write some_function
, or an expression involving percentage_chance
, in order to solve this problem?
推荐答案
你可以使用 random.random
:
You could use random.random
:
import random
if random.random() < percentage_chance:
print('aaa')
这篇关于采取行动的机会百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文