Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions bailey_wiseman/dojofiles/OOP/animal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
class animal(object):
def __init__(self, name, health):
self.name = name
self.health = health

def display(self):
print 'Hit Points...', self.health
print ''
return self

def walk(self):
print 'Walking...'
self.health -= 1
return self

def run(self):
print 'Running...'
self.health -= 5
return self

animal1 = animal('adsd', 100)
animal1.walk().walk().walk().run().run().display()

class dog(animal):
def __init__(self, name, health):
super(dog, self).__init__(name, health)
self.name = name
self.health = health

def pet(self):
print 'Petting...'
self.health += 5
return self

dog1 = dog('spot', 150)
dog1.walk().walk().pet().run().display()

class dragon(animal):
def __init__(self, name, health):
super(dragon, self).__init__(name, health)

def fly(self):
print 'Flying...'
self.health -= 10
return self

dragon1 = dragon('ajis', 170)
dragon1.fly().fly().fly().display()

class bear(animal):
def __init__(self, name, health):
super(bear, self).__init__(name, health)

def climb(self):
print 'Climbing...'
self.health -= 15
return self

bear1 = bear('misha', 800)
bear1.walk().walk().walk().climb().climb().climb().climb().display()
29 changes: 29 additions & 0 deletions bailey_wiseman/dojofiles/OOP/bike.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class bike(object):
def __init__(self, price, max_speed, miles=0):
self.price = price
self.max_speed = max_speed
self.miles = miles

def display(self):
print 'Price:...', self.price, 'Max_Speed:...', self.max_speed, 'Miles:...', self.miles
return self

def ride(self):
print 'Riding...'
self.miles += 10
return self

def reverse(self):
if self.miles == 0:
print 'Already at zero! Cannot reverse any further!...'
else:
print 'Reversing...'
self.miles -= 5
return self

instance1 = bike('200$', '30mph')
instance2 = bike('400$', '42mph')
instance3 = bike('900$', '51mph')
instance1.ride().ride().ride().reverse().display()
instance2.ride().ride().reverse().reverse().display()
instance3.reverse().reverse().reverse().display()
59 changes: 59 additions & 0 deletions bailey_wiseman/dojofiles/OOP/calls/calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class Call(object):
def __init__(self, callid, name, phone, time, purpose):
self.callid = callid
self.name = name
self.phone = phone
self.time = time
self.purpose = purpose

def display(self):
print 'Caller-ID :', self.callid
print 'Name :', self.name
print 'Phone# :', self.phone
print 'Call-time :', self.timeCall
print 'Purpose :', self.purpose
print ''
return self

def __str__(self):
return "Callid: {}, Name: {}, Phone: {}, Time: {}, Purpose: {}".format(
self.callid,
self.name,
self.phone,
self.time,
self.purpose
)

class Center(object):
def __init__(self):
self.data = []
self.queue = 0

def add_call(self, callid, name, phone, time, purpose):
print 'added call...'
call = Call(callid, name, phone, time, purpose)
self.data.append(call)
return self

def remove_call(self):
self.data.pop(0)
print 'removed call...'
return self

def info(self):
for call in center.data:
self.queue += 1
print 'queue:', self.queue
return self

center = Center()
center.add_call(1, 'joe', '214-667-4567', 1330, 'finance')
center.add_call(2, 'mary-ann', '214-869-1300', 1332, 'tech support')
center.add_call(3, 'alex', '543-443-7492', 1332, 'finance')
center.add_call(4, 'sin', '324-437-4531', 1335, 'n/a')
center.add_call(5, 'chris', '622-096-2544', 1336, 'tech support')

center.info().remove_call().info()
for call in center.data:
print call

32 changes: 32 additions & 0 deletions bailey_wiseman/dojofiles/OOP/car.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class car(object):
def __init__(self, price, speed, fuel, mileage, tax=1.12):
self.price = price
self.speed = speed
self.fuel = fuel
self.mileage = mileage
self.tax = tax
if self.price > 10000:
self.tax = (1.15)

def display(self):
print 'Price:...', self.price
print 'Speed:...', self.speed, 'MPH'
print 'Fuel:...', self.fuel
print 'Mileage:...', self.mileage, 'MPG'
print 'Tax:...', self.tax
print ''
return self

car1 = car(8000, 40, 'empty', 25)
car2 = car(18000, 80, 'low', 17)
car3 = car(3000, 20, 'empty', 13)
car4 = car(28000, 120, 'full', 20)
car5 = car(9900, 50, 'low', 22)
car6 = car(14200, 55, 'empty', 15)

car1.display()
car2.display()
car3.display()
car4.display()
car5.display()
car6.display()
63 changes: 63 additions & 0 deletions bailey_wiseman/dojofiles/OOP/hospital.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
class Patient(object):
def __init__(self, p_id, name, allergies, bed=[]):
self.p_id = p_id
self.name = name
self.allergies = allergies
self.bed = bed
self.patient_info = {'p_id': self.p_id, 'name': self.name, 'allergies': self.allergies, 'bed': self.bed,}

def __str__(self):
return "p_id: {}, Name: {}, allergies: {}, bed: {}".format(
self.p_id,
self.name,
self.allergies,
self.bed,
)

class Hospital(object):
def __init__(self, building, capacity):
self.info = []
self.building = building
self.capacity = capacity
self.myid = []

def admit(self, p_id, name, allergies, bed):
patient = Patient(p_id, name, allergies, bed)
print 'admited patient {}, {}'.format(name, p_id)
print ''
self.info.append(patient)
self.myid.append(p_id)
return self

def discharge(self, p_id):
print self.myid
if p_id == self.myid:
self.info.pop(patient)
self.myid.pop(p_id)
print self.myid
print ''
print 'removed patient', self.info
print ''
self.capacity += 1
return self

def display(self):
print 'Building: {}, Max Capacity: {}'.format(self.building, self.capacity)
print ''
for i in self.info:
print 'patient info:', i
return self

hospital = Hospital('st.johns', 5)

hospital.admit(2, 'jack', 'penicillin', [1])
hospital.admit(3, 'mike', 'asprin', [2])
hospital.admit(4, 'doug', 'penicillin', [3])
hospital.admit(5, 'louise', 'latex', [4])
hospital.admit(6, 'malley', 'penicillin, latex, oxiodants', [5])

hospital.display()

hospital.discharge(1)

hospital.display()
22 changes: 22 additions & 0 deletions bailey_wiseman/dojofiles/OOP/mathdojo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class mathdojo(object):
def __init__(self, mysum=0):
self.mysum = mysum


def add(self, *args):
for i in args:
if type(i) == int:
self.mysum += i
return self

def subtract(self, *args):
for i in args:
if type(i) == int:
self.mysum -= i
return self
def result(self):
print 'SUM...', self.mysum
return self

md = mathdojo()
md.add(2).add(2, 5).subtract(3, 2).result()
53 changes: 53 additions & 0 deletions bailey_wiseman/dojofiles/OOP/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class product(object):
def __init__(self, price, item, weight, brand, cost, status='For Sale'):
self.price = price
self.item = item
self.weight = weight
self.brand = brand
self.cost = cost
self.status = status

def display(self):
print 'Price:...', self.price
print 'Item:...', self.item
print 'Weight:...', self.weight
print 'Brand:...', self.brand
print 'Cost:...', self.cost
print 'Status:...', self.status
print ''

return self

def sell(self):
self.status = 'Sold'

return self

def tax(self):
self.price = self.price * 1.08
print 'Price after tax:...', self.price
return self

def itemreturn(self, refund):
if refund == 'defective':
self.status = 'defective'
self.price = 0
elif refund == 'like_new':
self.status = 'For Sale'
elif refund == 'used':
self.status = 'used'
self.price = self.price * 0.8

return self

product1 = product(200, 'Kayak', '85lbs', 'Alqui', 200)
product2 = product(20, 'Teapot', '5lbs', 'Sern', 20)
product3 = product(2000, 'Office Chair', '15lbs', 'Office Mate', 2000)
product4 = product(60, 'SunRoof', '30lbs', 'Shade Masters', 60)
product5 = product(180, 'Monitor', '12lbs', 'Hoffs', 180)

product1.tax().sell().display()
product2.itemreturn('defective').display()
product3.tax().sell().display()
product4.itemreturn('like_new').display()
product5.itemreturn('used').display()
24 changes: 24 additions & 0 deletions bailey_wiseman/dojofiles/python/checkerboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Assignment: Checkerboard
# Write a program that prints a 'checkerboard' pattern to the console.

# Your program should require no input and produce console output that looks like so:

# * * * *
# * * * *
# * * * *
# * * * *
# * * * *
# * * * *
# * * * *
# * * * *
# Copy
# Each star or space represents a square. On a traditional checkerboard you'll see alternating squares of red or black.
# In our case we will alternate stars and spaces. The goal is to repeat a process several times. This should make you think of looping.

def checkers(pattern1, pattern2):
for i in range(0, 100):
if i % 2 != 0:
print(pattern1)
else:
print(pattern2)
checkers('* * * *', ' * * * *')
17 changes: 17 additions & 0 deletions bailey_wiseman/dojofiles/python/coin_toss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import random

def start(myrange):
tails = 0
heads = 0
total = heads + tails
for i in myrange:
flip = random.randrange(1, 3)
if flip == 1:
tails += 1
total = heads + tails
print('Attempt #', total, 'out of', len(myrange), 'Throwing coin... It is Tails!...', 'Got', heads, 'Head(s) so far and', tails, 'Tail(s) so far!')
elif flip == 2:
heads += 1
total = heads + tails
print('Attempt #', total, 'out of', len(myrange), 'Throwing coin... It is Heads!...', 'Got', heads, 'Head(s) so far and', tails, 'Tail(s) so far!')
start(range(0, 5000))
Loading