From 1ee37b40236524bfc9bc6834cf6e2577dca4de30 Mon Sep 17 00:00:00 2001 From: william Date: Mon, 24 Nov 2014 14:57:16 -0500 Subject: [PATCH] ex 1 part 1 --- exercises/1-monty-hall-problem/README.md | 2 + .../__pycache__/models.cpython-34.pyc | Bin 0 -> 1388 bytes .../__pycache__/views.cpython-34.pyc | Bin 0 -> 1415 bytes exercises/1-monty-hall-problem/controller.py | 52 +++++++++++++++++- exercises/1-monty-hall-problem/default.db | Bin 0 -> 3072 bytes exercises/1-monty-hall-problem/models.py | 37 +++++++++++++ exercises/1-monty-hall-problem/schema.sql | 6 ++ exercises/1-monty-hall-problem/views.py | 25 ++++++++- 8 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 exercises/1-monty-hall-problem/__pycache__/models.cpython-34.pyc create mode 100644 exercises/1-monty-hall-problem/__pycache__/views.cpython-34.pyc create mode 100644 exercises/1-monty-hall-problem/default.db create mode 100644 exercises/1-monty-hall-problem/schema.sql diff --git a/exercises/1-monty-hall-problem/README.md b/exercises/1-monty-hall-problem/README.md index 292b08a..e4105c8 100644 --- a/exercises/1-monty-hall-problem/README.md +++ b/exercises/1-monty-hall-problem/README.md @@ -1,3 +1,5 @@ +50/50 for ever door all the time! + The Monty Hall Problem ====================== diff --git a/exercises/1-monty-hall-problem/__pycache__/models.cpython-34.pyc b/exercises/1-monty-hall-problem/__pycache__/models.cpython-34.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4c5993993629163a352271118b9103b480fe308e GIT binary patch literal 1388 zcmZ8gO>^8t5be?Ddf9wnDyHB-?GaUZy-9@&6qTex2$dX`Ds~UlUR1I)j^#)zXGV*$ z%RV_r{scyE-o4I@pfr+cQ={oeH7qdUXDezS`|e33up*1%exVcID~ zfmcZ-vK0BD@TBnNJxsn_da_hf1X6^wEa6fzPogUvl37l<86K2pnD#3OjlDRxIf0No z?K32TQFkGW$myXJF`^E-@I})Yn=>~KemTFxv=rx_oQtF`TPjM<@j~&W_2mdLUGB)5 z#*p$Tl1m)KGG;#WB$&OtQiyfM$oOZl%4*$3_M~j{!){=8rSn!7U1YLV(bQecZ@Fqa zKhI1zJZx;6wkM@+yRGI}uhIf3Cw>>;;DLz|(}WPei@A%>Kd+~UO|7RVWmT0~J>Acy z`#Ljra-#Ly$CDyEeKgg-YLk~%+v%f8-K^Tv$zfJilVj8DSGu0oO`$8hcYN9n(zINa zZJGv%Y=;n{w%qeTo!xcN?QOQ?ERln>uu{TjpFp(01k~X5Nbki4!y`}LdSV}bfb_`c z(tP7E42aRS}dr?3Abx;%4-h7kpk=*2y1^mAGs7PYOuP(yWg zzc1hh-|G@s3V-KHcnyWL_ENbdccpcVBWJpB4U}B^qIg&T??KV@crtgl!JjQ&q726y zE9k>z1LN_s?PVGZYdnZ0!qx zgC6O5S8@@^c_1Ji%wC{VLIHYcPXNfC^5npEzv3oGztci)S7_mR63z^XIU5%GAX``M zUa^1n^{d(Z`=1u$SF^>B<2R_+j=yAayW_sScE`Yks3qfHvT9BD(_K8tcma%J`>rZm z{dgJY&1!`%Tt@lY*v2el^hmyLH4IH%mu(m3RbzD$-SD)GKZG_r$Z8odM5ppwC^`U1 w*XNj)n2H*C_b@;6hTc#a`Vzmt(gf8RZUwlep&NYLQ}~1kSl-Q%_sOUK0*a^(U;qFB literal 0 HcmV?d00001 diff --git a/exercises/1-monty-hall-problem/__pycache__/views.cpython-34.pyc b/exercises/1-monty-hall-problem/__pycache__/views.cpython-34.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e1233a1ca541684070119c0f866b3c004ab325b7 GIT binary patch literal 1415 zcmbVL&2G~`5MC!vnmSIADg-@lI5mgFD!o;RB7p>zAgYu?Ays6#-XU3aV~1U*Ar`lC z}$M9tzV z6YETP7UR!46TZbYCK|Zs#=?CiVHP_-_oX-O{1}(nK#>(J9p>Qfy;iB4-#Z2sr(@t* z%Ciyh7ip5s`LjqVeyGz^1>8 zHtiX}*=}1z^PK?RgN~&E6YR9d6uLda(CtYPIygtRrZbr@YGEi7nS~+IH6)mmHz=9T zrRL_WJhWV9Wi#43R1g{9kYu3wJe_KuL}S?Fl!r_vQ_MqC3vCjGsNmQ9!HZaF?@=aT+D+aNxBI@Z)%TB>If@QrNL?0Z6TnXVET7>+|gnBKv zn{OZCP>fQOacVQya1M&kMxcSG3GiVWWn7w0r;~S%)2R|vaIWN;9jJH|B||8BfP;hC z$~4*MCrL0L?5UzK~BO+lolP2>q4_gCDpYHsYEx|8~_{LN4 zr(St)ko)mLx7lpw8;4kF9t|Uz?4QgBf6<=mOeP8FO(M4JOWl$xH2+ShPK2JP2L6vx zMWL&{bA^y+30XzAwNB@bCO!-oUKoy3F;#^9Fnl+SRH4yT44`S;^g4+;2`ayCkf2mo p1f3mCm8WIM%y;}U-mYKuU90Khe3N#?%LXY9;e&$3L+g)L><6KmBLe^c literal 0 HcmV?d00001 diff --git a/exercises/1-monty-hall-problem/controller.py b/exercises/1-monty-hall-problem/controller.py index 2de7b42..345a34a 100644 --- a/exercises/1-monty-hall-problem/controller.py +++ b/exercises/1-monty-hall-problem/controller.py @@ -1,6 +1,52 @@ -#from models import +from models import Doors from views import View class Controller: - def __init__(self): - pass \ No newline at end of file + def __init__( self ): + self.view = View() + self.name = self.view.get_name() + self.start() + + def start( self ): + + selected = int( self.view.display_doors() ) + self.doors = Doors( selected, self.name ) + + self.host_twist() + + return True + + def host_twist( self ): + + message ="" + + for i in range( 1, 4 ): + + if i == self.doors.selected: + message += "[ X ] " + elif i == self.doors.open_door: + message += "[ Goat ] " + else: + message += "[ " + str(i) + " ] " + other_selection = i + + selection = self.view.host_twist( message ) + + if selection: + self.doors.selected = other_selection + self.doors.switch = True + return self.out_come() + + def out_come( self ): + if self.doors.out_come(): + do = self.view.winner() + else: + do = self.view.loser() + + if do == 'n': + exit() + + self.start() + return True + +Controller() diff --git a/exercises/1-monty-hall-problem/default.db b/exercises/1-monty-hall-problem/default.db new file mode 100644 index 0000000000000000000000000000000000000000..cf5b656dac44f30c998a3296ff11a302eebd3fd2 GIT binary patch literal 3072 zcmeHJK}*9h6n;sjVyWzy>pO0&!iER0R*j?B)vcyrPtw(@g>GfGLp7J^h^b6QX1r6=M?{Q#Aw|S>S!ZI3XNioY*FI*SNY@STxb;?eBVM~G1K6VAJ)wZV5 zB(apT{cMpP&N+EGtna*2`JxVVMPH||Wu!OgcvAF*kEi0y4qS;|;JP^Uoq_F#crHS; z19{362?jW17Y7zvuHK| literal 0 HcmV?d00001 diff --git a/exercises/1-monty-hall-problem/models.py b/exercises/1-monty-hall-problem/models.py index e69de29..e23763b 100644 --- a/exercises/1-monty-hall-problem/models.py +++ b/exercises/1-monty-hall-problem/models.py @@ -0,0 +1,37 @@ +import random + +class Doors: + def __init__( self, selected, name ): + self.name = name + self.switch = False + self.selected = selected + self.car = random.randint( 1,3 ) + self.open_door = self.host_twist() + + def host_twist( self ): + open_door = random.randint( 1,3 ) + if open_door == self.car or open_door == self.selected: + return self.host_twist() + return open_door + + def out_come( self ): + + if self.selected == self.car: + logDB( self.name, self.switch, True) + return True + else: + logDB( self.name, self.switch, False) + return False + +def logDB( name, switch, outcome ): + import sqlite3 + + conn = sqlite3.connect('default.db') + c = conn.cursor() + + c.execute( "INSERT INTO games (name, switch, outcome) values (?,?,?) ", ( name, switch, outcome ) ) + + conn.commit() + + conn.close() + return True \ No newline at end of file diff --git a/exercises/1-monty-hall-problem/schema.sql b/exercises/1-monty-hall-problem/schema.sql new file mode 100644 index 0000000..d9a373b --- /dev/null +++ b/exercises/1-monty-hall-problem/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE games ( +id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, +name TEXT DEFAULT NULL, +switch TEXT DEFAULT NULL, +outcome TEXT DEFAULT NULL +); diff --git a/exercises/1-monty-hall-problem/views.py b/exercises/1-monty-hall-problem/views.py index ee133c7..301aed5 100644 --- a/exercises/1-monty-hall-problem/views.py +++ b/exercises/1-monty-hall-problem/views.py @@ -1,3 +1,24 @@ class View: - def __init__(self): - pass \ No newline at end of file + def __init__( self ): + print( "Welcome to the Monty Hall Problem!") + + def get_name( self ): + return input( "Please enter your name: " ) + + def display_doors( self ): + print( 'Doors: [ 1 ] [ 2 ] [ 3 ]' ) + return input( 'Select door: ' ) + + 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]: ") + + def winner( self ): + print( "You WIN!!!" ) + return input("Play again?[y]") + + def loser( self ): + print( "You Lose!!!" ) + return input("Play again?[y]") \ No newline at end of file