Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
cc162109d2 | |||
6d232050e3 |
20
README.md
20
README.md
@ -1,27 +1,9 @@
|
|||||||
Week 3 Day 1
|
MVC
|
||||||
============
|
============
|
||||||
Schedule Today:
|
|
||||||
|
|
||||||
Morning
|
|
||||||
-------
|
|
||||||
Weekend Projects Review and Refactor
|
|
||||||
Monty Hall Problem
|
|
||||||
|
|
||||||
Afternoon
|
|
||||||
---------
|
|
||||||
Bank Software
|
|
||||||
SQL Challenge
|
|
||||||
|
|
||||||
#### Resources
|
#### Resources
|
||||||
|
|
||||||
[Optimizing SQL queries](http://beginner-sql-tutorial.com/sql-query-tuning.htm)
|
[Optimizing SQL queries](http://beginner-sql-tutorial.com/sql-query-tuning.htm)
|
||||||
|
|
||||||
[A cool article about your git history](http://mislav.uniqpath.com/2014/02/hidden-documentation/)
|
[A cool article about your git history](http://mislav.uniqpath.com/2014/02/hidden-documentation/)
|
||||||
|
|
||||||
[Reading for tonight - the coffee maker problem](http://www.objectmentor.com/resources/articles/CoffeeMaker.pdf)
|
|
||||||
|
|
||||||
#### Homework
|
|
||||||
|
|
||||||
Finish up your assignments for today.
|
|
||||||
[Also, read this](http://www.objectmentor.com/resources/articles/CoffeeMaker.pdf)
|
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
50/50 for ever door all the time!
|
|
||||||
|
|
||||||
The Monty Hall Problem
|
The Monty Hall Problem
|
||||||
======================
|
======================
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,57 +1,6 @@
|
|||||||
from models import Doors
|
#from models import
|
||||||
from views import View
|
from views import View
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.view = View()
|
pass
|
||||||
self.name = self.view.get_name()
|
|
||||||
self.start()
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
|
|
||||||
selected = False
|
|
||||||
while selected not in ['1', '2', '3']:
|
|
||||||
selected = self.view.display_doors()
|
|
||||||
|
|
||||||
self.doors = Doors(int(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 = False
|
|
||||||
while selection not in ['n', 'y', '']:
|
|
||||||
selection = self.view.host_twist(message).lower()
|
|
||||||
|
|
||||||
if selection == 'y':
|
|
||||||
self.doors.selected = other_selection
|
|
||||||
self.doors.switch = True
|
|
||||||
return self.out_come()
|
|
||||||
|
|
||||||
def out_come(self):
|
|
||||||
message = 'LOSE'
|
|
||||||
if self.doors.out_come():
|
|
||||||
message = 'WIN'
|
|
||||||
|
|
||||||
replay = self.view.out_come(message)
|
|
||||||
|
|
||||||
if replay in ['', 'y']:
|
|
||||||
return self.start()
|
|
||||||
|
|
||||||
return exit()
|
|
||||||
print('name:', __name__)
|
|
||||||
if __name__ == '__main__':
|
|
||||||
Controller()
|
|
Binary file not shown.
@ -1,58 +0,0 @@
|
|||||||
import sqlite3
|
|
||||||
import random
|
|
||||||
|
|
||||||
conn = sqlite3.connect('default.db')
|
|
||||||
c = conn.cursor()
|
|
||||||
|
|
||||||
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):
|
|
||||||
|
|
||||||
|
|
||||||
c.execute("INSERT INTO games (name, switch, outcome) values (?,?,?) ", (name, switch, outcome))
|
|
||||||
|
|
||||||
conn.commit()
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def seedDB():
|
|
||||||
c.execute("""
|
|
||||||
CREATE TABLE games (
|
|
||||||
id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT,
|
|
||||||
name TEXT DEFAULT NULL,
|
|
||||||
switch TEXT DEFAULT NULL,
|
|
||||||
outcome TEXT DEFAULT NULL
|
|
||||||
);
|
|
||||||
""")
|
|
||||||
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
seed = input('Seed the database[y/n]: ').lower()
|
|
||||||
if seed in ['y', 'yes']:
|
|
||||||
print('seeding')
|
|
||||||
seedDB()
|
|
||||||
|
|
||||||
exit()
|
|
@ -1,6 +0,0 @@
|
|||||||
CREATE TABLE games (
|
|
||||||
id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT,
|
|
||||||
name TEXT DEFAULT NULL,
|
|
||||||
switch TEXT DEFAULT NULL,
|
|
||||||
outcome TEXT DEFAULT NULL
|
|
||||||
);
|
|
@ -1,25 +1,3 @@
|
|||||||
class View:
|
class View:
|
||||||
def get_name(self):
|
def __init__(self):
|
||||||
print('\033c')
|
pass
|
||||||
print('Welcome to the Monty Hall Problem!')
|
|
||||||
return input('Please enter your name: ')
|
|
||||||
|
|
||||||
def display_doors(self):
|
|
||||||
print('\033c')
|
|
||||||
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('[n]: ')
|
|
||||||
|
|
||||||
def out_come(self, message):
|
|
||||||
print('You {}!!!'.format(message))
|
|
||||||
return input('Play again?[y]')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print('Please opne controller.py')
|
|
||||||
exit()
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
|||||||
Your Own Private Bank
|
|
||||||
======================
|
|
||||||
|
|
||||||
Welcome back! In this challenge you'll be creating a rich Python terminal app emulating bank software.
|
|
||||||
|
|
||||||
###Step 1: Database
|
|
||||||
Our DB schema for this challenge is simple. For now, we only need two tables - Users and accounts. A user can have many accounts. Users should have at minimum a username to log in to the app, a time when they were created, and a permissions level. An account should have a number and a balance. Design the schema in SQL designer if it helps you.
|
|
||||||
|
|
||||||
There's a file called create_db.py - write your sql that creates the db in there to keep everything organized.
|
|
||||||
|
|
||||||
###Step 2: Our program models
|
|
||||||
We need two different classes for users - a client, and a banker. A client should be able to view all their accounts, deposit and withdraw funds to and from their OWN accounts, and transfer money from their OWN accounts to another user account. A banker should be able to create accounts, deposit and withdraw funds from ANY user account, and transfer money between ANY two user accounts. A banker should not have any accounts (no co-mingling of funds) and a person should not see the superuser options that bankers have. How you want to design this is up to you. See [inheritance](http://www.jesshamrick.com/2011/05/18/an-introduction-to-classes-and-inheritance-in-python/)
|
|
||||||
|
|
||||||
I also strongly recommend that you have another class (see [static methods](https://julien.danjou.info/blog/2013/guide-python-static-class-abstract-methods)) or a module that handles only reading and writing to the database.
|
|
||||||
|
|
||||||
###Step 3: Controller and Views
|
|
||||||
Stick to the MVC pattern - No spaghetti code! Keep your code dry. There's alot of user choice options which could be alot of if/else statements - can you think of a better way?
|
|
||||||
|
|
||||||
Present a nice clean interface to the user for the options they are allowed to perform. Some extra account details would be nice to display - some ideas are how long the user has been a member of the bank, which banker created their account, etc.
|
|
@ -1,2 +0,0 @@
|
|||||||
import bank_models
|
|
||||||
import bank_views
|
|
@ -1 +0,0 @@
|
|||||||
import sqlite3
|
|
@ -1 +0,0 @@
|
|||||||
import sqlite3
|
|
@ -1,17 +0,0 @@
|
|||||||
Loan or No Loan?
|
|
||||||
================
|
|
||||||
|
|
||||||
Here is some people's last month bank statements. Query the database to answer the questions. Write methods to return all of the information to you. Don't do this manually.
|
|
||||||
|
|
||||||
* How many people are there in the database?
|
|
||||||
* What is each persons salary (return their name and salary)?
|
|
||||||
* What is each persons net income?
|
|
||||||
* How about their highest expense?
|
|
||||||
* What percent of their salary did they spend?
|
|
||||||
* What was the average price of their expenses (don't include salary)?
|
|
||||||
* How many expenses did each person have?
|
|
||||||
* How many things did each person buy in the first week of the month? How much money did they spend?
|
|
||||||
* How about in the last week?
|
|
||||||
* Print everything bought between $40 and $60.
|
|
||||||
* Using the mortgage calculator you built before (some adjustments will need to be made), how large of a house could each person afford on a 15 year mortgage at 4%, if they plan on saving $200 a month (assuming they keep their jobs and spend the same amount).
|
|
||||||
* Write the database to a csv.
|
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user