sofus.py

Created by alain-busser

Created on April 20, 2019

1.38 KB

Sofus est un langage de programmation basé sur la notion de variable. Une variable est un objet capable de varier. Pour cela on lui demande de varier, par un ordre clair et explicite. Par exemple si N est une variable de Sofus (créée par N=Variable(0) par exemple) on peut l’incrémenter classiquement par N=Variable(N.valeur+1) ou à la façon de Sofus par N.augmente_toi_de(1)


pourcents = "pourcents"
au_carre = 2
au_cube = 3
def a_la_puissance(n): return n

class Variable():
    def __init__(self,v):
        self.valeur = float(v)
    def __str__(self):
        return str(self.valeur)
    def __repr__(self):
        return str(self.valeur)
    def augmente_toi_de(self,d=1,mode=None):
        if mode == pourcents:
            self.valeur *= 1+d/100
        else:
            self.valeur += d
    def diminue_toi_de(self,d=1,mode=None):
        if mode == pourcents:
            self.valeur *= 1-d/100
        else:
            self.valeur -= d
    def multiplie_toi_par(self,d=2,mode=None):
        if mode == pourcents:
            self.valeur *= d/100
        else:
            self.valeur *= d
    def divise_toi_par(self,d=2,mode=None):
        if mode == pourcents:
            self.valeur /= d/100
        else:
            self.valeur /= d
    def eleve_toi(self,p=au_carre):
        self.valeur **= p
    def inverse_toi(self):
        self.valeur = 1/self.valeur
    def double_toi(self):
        self.valeur *= 2
    def triple_toi(self):
        self.valeur *= 3
    def decuple_toi(self):
        self.valeur *= 10

print("Variable()")
def augmente_toi_de(): pass
def diminue_toi_de(): pass
def multiplie_toi_par(): pass
def divise_toi_par(): pass
def eleve_toi(): pass
def inverse_toi(): pass
def double_toi(): pass
def triple_toi(): pass
def decuple_toi():pass

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.