Skip to content

Instantly share code, notes, and snippets.

@NickTikhomirov
Created February 16, 2020 19:52
Show Gist options
  • Save NickTikhomirov/ac34759aff5faf8908ee4ec472da215b to your computer and use it in GitHub Desktop.
Save NickTikhomirov/ac34759aff5faf8908ee4ec472da215b to your computer and use it in GitHub Desktop.
my simple python program (first after hello world)
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