probabilty done

This commit is contained in:
2014-11-24 20:50:58 -05:00
parent 1ee37b4023
commit 47c104afec
13 changed files with 409 additions and 16 deletions

View File

@ -1,5 +1,10 @@
50/50 for ever door all the time!
[ total/ wins ]
switched [98179, 65319] not switched [97686, 32587] total [195865, 97906]
switched 66.53052078346693 % not switched 33.35892553692443 % all 49.98647027289204 %
The Monty Hall Problem
======================

View File

@ -46,7 +46,7 @@ class Controller:
if do == 'n':
exit()
self.start()
return self.start()
return True
Controller()

View File

@ -0,0 +1,4 @@
for (( c=1; c<=100000; c++ ))
do
python3 controller.py
done

View File

@ -18,6 +18,7 @@ class Doors:
if self.selected == self.car:
logDB( self.name, self.switch, True)
return True
else:
logDB( self.name, self.switch, False)

View File

@ -0,0 +1,28 @@
import sqlite3
conn = sqlite3.connect('default.db')
c = conn.cursor()
switched = [ 0, 0 ]
no_swich = [ 0, 0 ]
total = [ 0, 0 ]
c.execute( "SELECT * FROM games " )
result = c.fetchall()
for i in result:
if int( i[ 2 ] ) == 1:
# switched
switched[0] += 1
switched[1] += int( i[3] )
else:
# not switched
no_swich[0] += 1
no_swich[1] += int( i[3] )
total[0] += 1
total[1] += int( i[3] )
conn.commit()
c.close()
print( "switched", switched, "not switched", no_swich, "total", total)
print( 'switched', ( switched[1]/switched[0] )*100, "% not switched", ( no_swich[1]/no_swich[0] )*100, "% all", ( total[1]/total[0] )*100, "%" )

View File

@ -1,24 +1,21 @@
import random
class View:
def __init__( self ):
print( "Welcome to the Monty Hall Problem!")
pass
def get_name( self ):
return input( "Please enter your name: " )
return "computer"
def display_doors( self ):
print( 'Doors: [ 1 ] [ 2 ] [ 3 ]' )
return input( 'Select door: ' )
return random.randint( 1,3 )
def host_twist( self, message ):
print( "The host will revel where one goat is..." )
print( message )
print( "Would you like to change your selection? [n/y]" )
return input( "[no]: ")
return bool(random.getrandbits(1))
def winner( self ):
print( "You WIN!!!" )
return input("Play again?[y]")
return ''
def loser( self ):
print( "You Lose!!!" )
return input("Play again?[y]")
return 'n'