import random
def xuanze():
k = [1, 1, 2]
random.shuffle(k)
xuan = random.randint(0, 2)
k.remove(k[xuan])
k.pop(k.index(1))
o = k[0]
if o == 2:
return True
return False
def buxuan():
k = [1, 1, 2]
random.shuffle(k)
xuan = random.randint(0, 2)
if k[xuan] == 2:
return True
return False
p = [xuanze() for i in range(10000)]
q = [buxuan() for i in range(10000)]
xuan1 = p.count(True)
xuant = q.count(True)
print("{:.3f}%".format(xuan1 / len(p) * 100))
print("{:.3f}%".format(xuant / len(q) * 100))
直接模拟,证明成功
确实大约是66% |