Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyTempConvDIP
#python 3.6.9 #PyTempConvDIP: example of SOLID principle where Dependency Inversion Principle is highlighted;high level module depends on abstraction ,not on low level module; #this code is created by Rezaul Hoque on April 16,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 TempChange(ABC): def change(self, from_scale, to_scale, temp) -> float: pass class Cel2Far(TempChange): def change(self, from_scale, to_scale, temp) -> float: print('Converting temperature from Celsius to Fahrenheit with Cel2Far:') print(f'{temp} {from_scale} = {9*temp/5+32} {to_scale}') return 9*temp/5+32 class Far2Cel(TempChange): def change(self, from_scale, to_scale, temp) -> float: print('Converting temperature from Fahrenheit to Celsius with Far2Cel:') print(f'{temp} {from_scale} = {5*(temp-32)/9} {to_scale}') return 5*(temp-32)/9 class Cel2Kel(TempChange): def change(self, from_scale, to_scale, temp) -> float: print('Converting temperature from Celsius to Kelvin with Cel2Kel:') print(f'{temp} {from_scale} = {temp+273.15} {to_scale}') return temp+273.15 class Kel2Cel(TempChange): def change(self, from_scale, to_scale, temp) -> float: print('Converting temperature from Kelvin to Celsius with Kel2Cel:') print(f'{temp} {from_scale} = {temp-273.15} {to_scale}') return temp-273.15 class Far2Kel(TempChange): def change(self, from_scale, to_scale, temp) -> float: print('Converting temperature from Fahrenheit to Kelvin with Far2Kel:') print(f'{temp} {from_scale} = {5*(temp+459.67)/9} {to_scale}') return 5*(temp+459.67)/9 class Kel2Far(TempChange): def change(self, from_scale, to_scale, temp) -> float: print('Converting temperature from Kelvin to Fahrenheit with Kel2Far:') print(f'{temp} {from_scale} = {9*temp/5-459.67} {to_scale}') return 9*temp/5-459.67 class HighMod: def __init__(self, changer: TempChange): self.changer = changer def disp(self): self.changer.change('°C', '°F', 30) if __name__ == '__main__': changer = Cel2Far() a = HighMod(changer) a.disp()
run
|
edit
|
history
|
help
0
even no
benda x guna
thermal_containers
Python | Random elements with atleast K occurrences
Pytest
Questions
Iterator-1
Mengira luas dan perimeter segi tiga
Dont know, Dont care
Hello world