Monty hall simulation returning 50% odds?
问题 from random import randint numberOfDoors = 3 success = 0 attempts = 0 while True: try: doors = [0] * numberOfDoors doors[randint(0, numberOfDoors - 1)] = 1 chosen = randint(0, numberOfDoors - 1) while numberOfDoors > 2: notIn = -1 while notIn == -1: index = randint(0, numberOfDoors - 1) if doors[index] == 0 and index != chosen: notIn = index if notIn < chosen: chosen -= 1 del doors[notIn] numberOfDoors -= 1 # doors is 2, so not chosen (0 or 1) will return the opposite (1 or 0) success +=