|
#!/usr/bin/python
#coding:utf-8
total=100000
a=b=c=d=e=f=0.00
x=0
from random import randint
list=["sheep1","sheep2","car"]
tuple=("yes","no")
while x!=total:
t=randint(0,2)
i=randint(0,1)
# print list[t],tuple
if list[t]=="car":
if tuple=="yes":
a+=1
else:
b+=1
elif list[t]=="sheep1":
if tuple=="yes":
c+=1
else:
d+=1
elif list[t]=="sheep2":
if tuple=="yes":
e+=1
else:
f+=1
x+=1
print "总次数为%d"%(total)
print "换%d" %(a+c+e),"不换%d" %(b+d+f)
print "不换赢的概率为%.2f%%"%(b/(c+b+e)*100)
print "换赢的概率为%.2f%%"%((c+e)/(c+b+e)*100) |
|
|