我不明白我在真正的Python书中找到的这种语法,并希望我可以得到一些清晰。真正的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%的获胜几率。但随机()< .87如何定义A会得到87%?
当我看到它,它指出: 如果随机小于0.87
这是我希望澄清,因为随机小于0.87没有道理给我。
很好的答案谢谢 – sayth 2013-03-26 09:58:53