Monty Hall problem: Difference between revisions

Line 2,477:
Not switching allows you to win 33337 out of 100000 times.
Switching allows you to win 66529 out of 100000 times.</pre>
 
 
#Another simpler(my opinion) way to do this is below, also in python 3:
 
import random
# 1 represents a car
# 0 represent a goat
 
stay = 0 # amount won if stay in the same position
switch = 0 # amount won if you switch
 
for i in range(1000):
lst = [1,0,0] # one car and two goats
random.shuffle(lst) # shffles the list randomly
ran = random.randrange(3) # gets a random number for the random guess
 
user = lst[ran] #storing the random guess
 
del(lst[ran]) # deleting the random guess
 
huh = 0
for i in lst: # getting a value 0 and deleting it
if i ==0:
del(lst[huh]) # deletes a goat when it finds it
break
huh+=1
if user ==1: # if the original choice is 1 then stay adds 1
stay+=1
if lst[0] == 1: # if the switched value is 1 then switch adds 1
switch+=1
 
print("Stay =",stay)
print("Switch = ",switch)
# Done by Sam Witton
 
=={{header|R}}==