import random
import sys
bestcounter1 = 0
bestcounter2=0
get_sample = int(sys.argv[1])
for i in range(get_sample):
for i in range(12):
if (random.randint(1,6)==1):
bestcounter1+=1
bestcounter2+=1
oneatleasttwice = (bestcounter2*1.0)/(2*(get_sample))
#Divide by 2 to make both comparable. Otherwise 2 will always be greater than 1 !
print("One atleast twice in 12 rolls: ", oneatleasttwice)
有人能解释一下这里使用的逻辑是否正确吗?我得到的输出总是在1左右。在
谢谢
你必须把你的柜台放在正确的地方。假设}用于在获得2个或更多值1时计算运行次数。那么主for循环应该如下所示:
bestcounter1
用于在每次运行(12次转鼓)期间计数1的值,而{我得到了61.9%的结果100万次。在
相关问题 更多 >
编程相关推荐