Created
September 16, 2020 13:28
-
-
Save AtufaShireen/39d9478aa0fd794f446556f7c10036c9 to your computer and use it in GitHub Desktop.
This file contains 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
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