I'm doing the Thinkful Python course at the moment and I can't figure out how to use the self attribute of one class in another class.
class Bicycle(object):
# Have a model name
# Have a weight
# Have a cost to produce
def __init__(self, model):
self.model = model
pass
class BicycleShop(object):
# Create a bicycle shop that has 6 different bicycle models in stock. The shop should charge its customers 20% over the cost of the bikes
margin = 1.2
# Have a name
# Have an inventory of different bikes
# Sell bikes with a margin over their cost
# Can see a total of how much profit they have made
def __init__(self, company_name, models):
self.company_name = company_name
self.models = models
def bicycle_models(self):
for model in self.models.keys():
print(model)
def bicycle_prices(self):
for model, price in self.models.items():
if price <= customer_1.budget:
print("The {} is available for a price of ${:.2f}.".format(model, price * self.margin))
class Customer(object):
# Have a name
# Have a fund of money used to purchase the bike
# Can buy and own a new bicycle
def __init__(self, name, budget):
self.name = name
self.budget = budget
def check_funds(self):
return evans_cycles.bicycle_prices()
evans_cycles = BicycleShop("Evans Cycles", { "BMC Road Machine": 125, "Cannondale Synapse": 275, "Pinnacle Laterite": 450, "Fuji Transonic": 625, "Cervelo R2": 750, "Specialized Roubaix": 999 })
print("\nWe are {} Bicycle Shop. Please see our range of bikes, below.\n".format(evans_cycles.company_name))
evans_cycles.bicycle_models()
customer_1 = Customer('Stuart', 1000)
print("\nHello, I'm {} and my budget is ${}. What can I afford?\n".format(customer_1.name, customer_1.budget))
print(customer_1.check_funds())
Currently, I have hard coded in customer_1.budget into the bicycle_prices method and evans_cycles into the check_funds function. But I'm aware this is not the correct way to do it, but I can't figure out how to do it any other way.
What is the correct way to utilize attributes of one class in another? I have tried to use inheritance, but it didn't work, it would not accept my dictionary as a parameter I think.