Created
January 29, 2020 22:37
-
-
Save ilkermanap/f063b4fc7d60216d1c5b242d9048cd21 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def toplama(a,b): | |
return a+b | |
def carpma(a,b): | |
return a*b | |
class Komut: | |
def __init__(self): | |
self.liste = [] | |
self.func = None | |
def kontrol(self, metin): | |
return metin in self.liste | |
def ekle(self, metin): | |
if metin not in self.liste: | |
self.liste.append(metin) | |
def islem(self, func): | |
self.func = func | |
def eylem(self, **kwargs): | |
return self.func(**kwargs) | |
class Komutlar: | |
def __init__(self): | |
self.komutlistesi = [] | |
def ekle(self, komut): | |
self.komutlistesi.append(komut) | |
def eylem(self, metin, **kwargs): | |
for k in self.komutlistesi: | |
if k.kontrol(metin): | |
return k.eylem(**kwargs) | |
if __name__ == "__main__": | |
islemler = Komutlar() | |
crp = Komut() | |
crp.ekle("carp") | |
crp.islem(carpma) | |
islemler.ekle(crp) | |
tpl = Komut() | |
tpl.ekle("topla") | |
tpl.islem(toplama) | |
islemler.ekle(tpl) | |
print(islemler.eylem("carp", a=10, b=100)) | |
print(islemler.eylem("topla", a=10, b=100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment