Skip to content

Instantly share code, notes, and snippets.

@notsobad
Created August 28, 2020 03:27
Show Gist options
  • Save notsobad/87bf10ff73a70475e8f528111fe29707 to your computer and use it in GitHub Desktop.
Save notsobad/87bf10ff73a70475e8f528111fe29707 to your computer and use it in GitHub Desktop.
#coding=utf-8
# https://zh.wikipedia.org/wiki/%E8%92%99%E6%8F%90%E9%9C%8D%E7%88%BE%E5%95%8F%E9%A1%8C
import sys
import random
stay = 0
change = 0
MAX_TRY = int(sys.argv[1])
for i in range(MAX_TRY):
# 大奖
real = random.randint(0, 2)
# 选择
choice = random.randint(0, 2)
# 主持人打开一个没有奖品的门之后,面临两种选择,坚持或者改变
# 坚持选择时,获胜的情况仅为 real == choice
# 当 real != choice 时,改变可以获得大奖
if real == choice:
stay += 1
else:
change += 1
print(float(stay)/MAX_TRY, float(change)/MAX_TRY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment