Created
June 24, 2016 21:05
-
-
Save dardevelin/8ce7993237a964f3fe5ea6384222c6ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Bicycle industry classes | |
class Bike_shop(object): | |
def __init__(self, name, inventory = None): | |
self.name = name | |
self.margin = 0.2 | |
if None == inventory: | |
self.inventory = [] | |
else: | |
self.inventory = inventory | |
def add_bicycle(self, bicycle): | |
'''Adds bicycle to inventory''' | |
for bike in self.inventory: | |
if bike.model == bicycle.model: | |
bike.weight = bicycle.weight | |
bike.cost = bicycle.cost | |
return | |
self.inventory.append(bicycle) | |
def show_inventory(self): | |
for item in self.inventory: | |
print("Name:{} | Weight:{} | Cost:{} \n".format(item.model, item.weight, item.cost)) | |
def filter_by_budget(self, budget): | |
shortlist = [] | |
for item in self.inventory: | |
if budget >= item.cost + (item.cost * self.margin): | |
shortlist.append(item) | |
return shortlist | |
def remove_bicycle(self, model): | |
'''Removes bicycle to inventory''' | |
def sell_bicycle(self, model): | |
'''Sells specific bike model to customer''' | |
class Bicycle(object): | |
def __init__(self, model, weight, cost): | |
self.model = model | |
self.weight = weight | |
self.cost = cost | |
class Customer(object): | |
def __init__(self, name, budget, collection = None): | |
'''Creates a customer with the default parameters. | |
Checks if customer has a bike based on the value of collection.''' | |
self.name = name | |
self.budget = budget | |
if None == collection: | |
self.collection = {} | |
self.has_bike = False | |
else: | |
self.collection = collection | |
self.has_bike = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bicycle import * | |
# Bike_shop attributes - name, inv, margin (% as decimal) | |
# Bicycle attributes - model, weight (lbs.), cost ($) | |
# Customer attributes - name, budget ($), has_bike (bool) | |
shop1 = Bike_shop("Wheelz N' Stuff") | |
shop1.add_bicycle( Bicycle('Schwinn', 20, 49.99) ) | |
shop1.add_bicycle( Bicycle('Trek', 15, 99.99) ) | |
shop1.add_bicycle( Bicycle('Giant', 17, 149.99) ) | |
shop1.add_bicycle( Bicycle('Fuji', 9, 399.99) ) | |
shop1.add_bicycle( Bicycle('GT', 10, 449.99) ) | |
shop1.add_bicycle( Bicycle('Kestrel', 10, 799.99) ) | |
lance = Customer('Lance Armstrong', 1000, False) | |
dave = Customer('Dave Mirra', 500, False) | |
matt = Customer('Matt Hoffman', 200, False) | |
def retail_price(model): | |
price = model.cost + model.cost * shop1.margin | |
print('${}'.format(round(price, 2))) | |
#retail_price(bike_6) | |
def print_shortlist(shortlist): | |
for item in shortlist: | |
print("Name:{} | Weight:{} | Cost:{} \n".format(item.model, item.weight, item.cost)) | |
if __name__ == "__main__": | |
lance_shortlist = shop1.filter_by_budget(lance.budget) | |
dave_shortlist = shop1.filter_by_budget(dave.budget) | |
matt_shortlist = shop1.filter_by_budget(matt.budget) | |
print("Lance can afford\n") | |
print_shortlist(lance_shortlist) | |
print("Dave can afford\n") | |
print_shortlist(dave_shortlist) | |
print("Matt can afford\n") | |
print_shortlist(matt_shortlist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment