-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (39 loc) · 1.22 KB
/
Copy pathmain.py
File metadata and controls
48 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import random
class MontyHallBot:
doors = [False, False, False]
wins = 0
losses = 0
repeats = 10000
def __init__(self):
self.runTest()
def runTest(self):
for i in range(self.repeats):
self.assignDoors()
self.userSelection()
self.openAnotherDoor()
self.switchUserPosition()
self.winOrLose()
print("WINS: " + str(self.wins))
print("LOSSES: " + str(self.losses))
print((self.wins/self.repeats)*100)
def assignDoors(self):
self.doors = ["Car", "Goat", "Goat"]
random.shuffle(self.doors)
def userSelection(self):
self.choice = random.randrange(3)
def openAnotherDoor(self):
for j, contents in enumerate(self.doors):
if(j != self.choice and contents == "Goat"):
self.reveal = j
break
def switchUserPosition(self):
for j, contents in enumerate(self.doors):
if(j != self.choice and j != self.reveal):
self.choice = j
break
def winOrLose(self):
if(self.doors[self.choice] == "Car"):
self.wins += 1
else:
self.losses += 1
bot = MontyHallBot()