Created
November 17, 2008 18:36
-
-
Save fajran/25857 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 Kalkulator: | |
def __call__(self, fungsi, a, b): | |
if fungsi == 'tambah': | |
return self.tambah(a, b) | |
if fungsi == 'kurang': | |
return self.kurang(a, b) | |
if fungsi == 'kali': | |
return self.kali(a, b) | |
if fungsi == 'bagi': | |
return self.bagi(a, b) | |
def tambah(self, a, b): | |
return a + b | |
def kurang(self, a, b): | |
return a - b | |
def kali(self, a, b): | |
return a * b | |
def bagi(self, a, b): | |
return float(a) / b | |
calc = Kalkulator() | |
print calc('tambah', 1, 2) | |
print calc('kurang', 1, 2) | |
print calc('kali', 1, 2) | |
print calc('bagi', 1, 2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment