我不明白我在真正的 python 书中找到的这种语法,并希望我能弄清楚。
from __future__ import division
from random import random
total_A_wins = 0
total_B_wins = 0
trials = 100000
for trial in range(0, trials):
A_win = 0
B_win = 0
if random() < .87: # 1st region
A_win += 1
else:
B_win += 1
# determine overall election outcome
if A_win > B_win:
total_A_wins += 1
else:
total_B_wins += 1
print "Probability A wins:", total_A_wins/trials
print "Probability B wins:", total_B_wins/trials
所以在练习中他们说 A 有 87% 的机会获胜。但是 random () < .87 如何定义 A 将获得 87% 呢?
当我读到它时,它说:如果随机数小于 0.87
这是我希望澄清的,因为随机小于 0.87 对我来说没有意义。