I want to convert (the original script)Procedure Oriented Script to Object Oriented, but I tried many times in many ways and I have failed every single time I will write the original script then i will write my try
Requirements
Bike attributes (the description and the bike cost and sale price and the bike condition).
Update the bike cost from 500 to 350.
Procedure Oriented:
def update_sale_price(bike, sale_price):
if bike['sold'] == True:
print('Action not allowed, Bike has already been sold')
else:
bike['sale_price'] = sale_price
def sell(bike):
bike['sold'] = True
def create_bike(description, cost, sale_price, condition):
return {
'description': description,
'cost': cost,
'sale_price': sale_price,
'condition': condition,
'sold': False
}
bike1 = create_bike('Univega Alpina, orange', cost=100, sale_price=500, condition=0.5)
update_sale_price(bike1, 350)
sell(bike1)
print(bike1)
Object Oriented (My try):
class create_bike:
def __init__(self, sale_price, description, cost, condition):
self.sale_price = sale_price
self.description = description
self.cost = cost
self.condition = condition
class update_sell_price:
def __init__ (self, bike, sale_price):
self.bike = bike
self.sale_price = sale_price
bike1 = create_bike(description='Univega Alpina, orange', cost=100, sale_price=500, condition=0.5)
up = update_sell_price(bike=bike1, sale_price=350)
print(up)