Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyFoodVatTip
#python 3.6.9 #PyFoodVatTip: example of SOLID and generator function #this code is created by Rezaul Hoque on April 27,2022. #contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com #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 class Food(): def __init__(self,name): self.name = name @property def fname(self): return f"{self.name}" class VatCo(ABC): def convert(self,vat:float,tip:int,total:int)->float: pass class WithoutVat(VatCo): def convert(self,vat2:float,tip2:int,total: int)->float: print(f'{total+tip2}') return total+tip2 class WithVat(VatCo): def convert(self,vat:float,tip:int,total: int)->float: print(f'{total+tip+total*vat}') return total+tip+total*vat class WithVatDeli(VatCo): def convert(self,vat:float,tip:int,total: int)->float: print(f'{total+tip+total*vat+150}') return total+tip+total*vat+150 class Transform: def __init__(self,converter:VatCo): self.converter=converter def disp(self): self.converter.convert(vat,tip,total) class Package(Food): def __init__(self,name,price,qty): super().__init__(name) self.price = price self.qty=qty def fprice(self): return self.price def fqty(self): return self.qty def fcost(self): return self.price*self.qty class Detail: def __init__(self): self.thelist= [ ] def add(self,pack): self.thelist.append(pack) #private method def __banner(self): print("You've ordered:\n") yield "~"*35 print("name price(TK) qty cost(TK)\n") yield "~"*35 def tot(self): total=0 for s in self.thelist: total += s.fcost() return total def display(self): for i in self.thelist: ##important:string objects are not callable like i.fname();they should be called like i.fname print(f"{i.fname}\t{i.fprice()}\t{i.fqty()}\t{i.fcost()}") def gen(): print("Example of SOLID and generator function") yield '#'*25 print("April 27,2022") yield 'π'*25 if __name__ == '__main__': m=gen() show=next(m) print(show) show=next(m) print(show) det = Detail() w=det._Detail__banner() show=next(w) print(show) show=next(w) print(show) det.add(Package('Dal Roti',25,1)) det.add(Package('Parota Korma',120,1)) det.add(Package('Naan Lotpoti',50,1)) det.add(Package('Malai Chaï',30,1)) det.display() print("-"*35) print("Total Cost ", det.tot()) total=det.tot() a=WithVat() b=WithVatDeli() #p=WithoutVat() vat=float(input("Enter vat:\n")) tip=float(input("Enter tip:\n")) #m=WithoutVat(v,t,total) #t=Transform(a) #print("Total (incl VAT & tip ):") #e.disp() #t.disp() #e=Transform(p) #print("Total (excl VAT but incl.tip ):") #e.disp() c=Transform(b) print("Total (incl. VAT,tip & delivery charge):") c.disp()
run
|
edit
|
history
|
help
0
Юра и заселение
5 ki table
inverse matrix gauss jordan
Komalsri123
IP Network & Broadcast Address Calculator 2
gj3
wordchangething
Skillenza - Marker Count
Faiha Lesson 1, 2020: Python Basics
NumPY01