Bicycle Classes

Run Settings
LanguagePython
Language Version
Run Command
class Bicycle: #Have a model name #Have a weight #Have a cost to produce def __init__(self,name,weight,prod_cost): self.name = name self.weight = weight self.prod_cost = prod_cost self.retail_cost = 0 def __repr__(self): return self.name class Shop: #Have a name #Have an inventory of different bicycles #Sell bicycles with a margin over their cost #Can see how much profit they have made from selling bikes def __init__(self,name,inventory,margin): self.name = name self.inventory = inventory self.margin = margin self.profit = 0 for bike in self.inventory.keys(): bike.retail_cost = int(self.margin * bike.prod_cost) class Customer: #Have a name #Have a fund of money to buy a bike #Can buy and own a new bicycle def __init__(self,name,funds): self.name = name self.funds = funds for money in self.inventory.keys(): money.wallet = self.funds - bike.retail_cost def purchase(self,bike,shop): shop.inventory[bike] -= 1 #BICYCLES: Name, Weight, Cost drift = Bicycle("Drift Bike",12,650) road = Bicycle("Road Bike",11,170) beach = Bicycle("Beach Bike",10,180) mountain = Bicycle("Mountain Bike",12,1600) bmx = Bicycle("BMX Bike",8,450) uni = Bicycle("Unicycle",5,250) #SHOP: Name, Inventory, Margin(profit) red_cycle = Shop("Red Cycle",{ drift: 1, road: 12, beach: 2, mountain: 14, bmx: 2, uni: 0 }, 1.1) #CUSTOMER: Name, Funds c1 = Customer("Steve",200) c2 = Customer("Jim",500) c3 = Customer("Joe",1000) #process example, inventory before and after purchase print(c1.funds) print (red_cycle.inventory) c1.purchase(drift, red_cycle) print ("The Drift Bike costs: " + str(drift.retail_cost)) print (red_cycle.inventory) print (c1.funds)
Editor Settings
Theme
Key bindings
Full width
Lines