Created
February 16, 2020 19:52
-
-
Save NickTikhomirov/ac34759aff5faf8908ee4ec472da215b to your computer and use it in GitHub Desktop.
my simple python program (first after hello world)
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
import math | |
class AbstractOperation: | |
def introduce(self) -> str: | |
return "" | |
def perform(self, a, b): | |
return a | |
class OperationSum(AbstractOperation): | |
def introduce(self) -> str: | |
return "a + b" | |
def perform(self, a, b): | |
return a + b | |
class OperationLog(AbstractOperation): | |
def introduce(self) -> str: | |
return "Log_a(b)" | |
def perform(self, a, b): | |
return math.log(b, a) | |
class OperationMult(AbstractOperation): | |
def introduce(self) -> str: | |
return "a * b" | |
def perform(self, a, b): | |
return a * b | |
class OperationXor(AbstractOperation): | |
def introduce(self) -> str: | |
return "a xor b" | |
def perform(self, a, b): | |
return a ^ b | |
class OperationPow(AbstractOperation): | |
def introduce(self) -> str: | |
return "a*a*...a (b times)" | |
def perform(self, a, b): | |
return a**b | |
def decorate(x, a, b): | |
op = x() | |
print(op.introduce(), "=", op.perform(a,b)) | |
S = [OperationSum, OperationMult, OperationPow, OperationXor, OperationLog] | |
for s in S: | |
decorate(s,5,3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment