Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyAbs
#python 3.6.9 #PyAbs #this code is created by Rezaul Hoque on January 09,2022;contact: jewelmrh@yahoo.com,Dhaka, Bangladesh #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; from abc import ABC,abstractmethod class Food(ABC): def __init__(self, food,color): self.food = food self.color = color @property def foodcol(self): return f"{self.food} \t {self.color}" @abstractmethod def cost(self): pass class CookedFood(Food): def __init__(self,food,color,price,qty): super().__init__(food,color) self.price = price self.qty = qty def cost(self): return self.price*self.qty class BakedFood(Food): def __init__(self,food,color,price,qty,charge): super().__init__(food,color) self.price = price self.qty = qty self.charge = charge def cost(self): return (self.price*self.qty)+self.charge class Detail: def __init__(self): self.foodlist= [ ] def add(self,food): self.foodlist.append(food) #private method def __banner(self): print("Example: Abstract class,abstract method and private method") print("~~~~~~~~~~~~~~~~~~~~~~~~") def display(self): for i in self.foodlist: print(f"{i.foodcol} \t {i.cost()}") if __name__ == '__main__': det = Detail() det._Detail__banner() det.add(CookedFood('Pakora','Yellow',5,4)) det.add(CookedFood('Jilebi','Golden',10,5)) det.add(BakedFood('Rice Cake','White',10,5,10)) det.add(BakedFood('Vanilla Cake','Brown',35,1,10)) det.display()
run
|
edit
|
history
|
help
0
Distance between latititude and longitude
Love
2.1.19
31 dec dil khush
kenken1
Guessing game
PySlots
mul table
try
Christmas tree