Skip to content

Instantly share code, notes, and snippets.

@AtufaShireen
Created September 16, 2020 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AtufaShireen/39d9478aa0fd794f446556f7c10036c9 to your computer and use it in GitHub Desktop.
Save AtufaShireen/39d9478aa0fd794f446556f7c10036c9 to your computer and use it in GitHub Desktop.
class RegularCustomer:
def __init__(self, name, item, price, quantity):
self.name = name
self.item = item
self.price = price
self.quantity = quantity
def discount(self):
return self.price * 0.3
def final(self):
return (self.price - self.discount()) * self.quantity
class OccasionalCustomer(RegularCustomer):
def __init__(self, name, item, price, quantity):
super().__init__(name, item, price, quantity)
def discount(self):
return self.price * 0.1
# common interface
def cal_discount(object):
z = object.discount()
print(f'{object.name}\'s discount will be {z}')
print(f'{object.final()} is your final price')
# instantiating objects for the two classes
cus_1 = RegularCustomer('Atufa', 'shoes', 600, 1)
cus_2 = OccasionalCustomer('Shireen', 'shoes', 600, 1)
# passing the objects to common interface
print(cal_discount(cus_1))
print(cal_discount(cus_2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment