# sofus_en.py

Created by alain-busser

Created on March 11, 2019

1.28 KB

Sofus is a programming language, inspired by Cobol, but object-programmed. It has variables, which have a value (a float), and can be inverted or raised by or lowered by or multiplied by or divided by or raised to the power, any constant increment/factor/power, or any other variable. Try for example

price = Variable(100) for n in range(100): price.raise_by(1,percents)

```percents = "percents"
thesquare = 2
thecube = 3
def thepower(n): return n

class Variable():
def __init__(self,v):
self.value = float(v)
def __str__(self):
return str(self.value)
def __repr__(self):
return str(self.value)
def raise_by(self,d=1,mode=None):
if hasattr(d,'value'):
d = d.value
if mode == None:
self.value += d
elif mode == percents:
self.value *= 1+d/100
def lower_by(self,d=1,mode=None):
if hasattr(d,'value'):
d = d.value
if mode == None:
self.value -= d
elif mode == percents:
self.value *= 1-d/100
def multiply_by(self,d=2,mode=None):
if hasattr(d,'value'):
d = d.value
if mode == None:
self.value *= d
elif mode == percents:
self.value *= d/100
def divide_by(self,d=2,mode=None):
if hasattr(d,'value'):
d = d.value
if mode == None:
self.value /= d
elif mode == percents:
self.value /= d/100
def raise_to(self,power=thesquare):
if hasattr(power,'value'):
power = power.value
self.value **= power
def invert(self):
self.value = 1/self.value```