diff --git a/1-table/models.py b/1-table/models.py new file mode 100644 index 0000000000000000000000000000000000000000..8747cafdd90217b95fd8605ec152cb0a2c64313b --- /dev/null +++ b/1-table/models.py @@ -0,0 +1,30 @@ +class Table(): + + def __init__(self,x_pos,y_pos): + self.couleur = '0a0a2a' + self.objets=[] + self.x_pos = x_pos + self.y_pos = y_pos + self.forme = 'rectangle' + self.orientation = (1,0) #dx,dy + self.matiere = 'bois' + + + def tourner_la_table(self,new_orientation): + (dx,dy)=new_orientation + if dx in [-1,0,+1] and dy in [-1,0,+1] and dx*dy!=0: + self.orientation = (dx,dy) + + def bouger_la_table(self,x_pos,y_pos): + if type(x_pos)==type(0) and type(y_pos)==type(0): + self.x_pos = x_pos + self.y_pos = y_pos + else: + raise Exception ("Invalid coordinates") + + +table=Table(5,5) + +table.bouger_la_table('aa',-5) + +print(table.x_pos,table.y_pos) diff --git a/1-table/presentation.md b/1-table/presentation.md index c76daee98715cda90f7a170be8e29c941bd7d057..c0feb5cbee0eefcc021fe88deded6d46c2aa88ce 100644 --- a/1-table/presentation.md +++ b/1-table/presentation.md @@ -8,15 +8,21 @@ On va prendre un objet concret, du monde réel : une **table**. ### Quels attributs ? -- -- +- dimension +- liste des objets dessus +- matière +- position +- forme +- orientation ### Quelles méthodes ? -- -- +- bouger la table +- tourner la table + + ### Que va t'on faire dans le constructeur ? - Initialiser les attributs -- \ No newline at end of file +- diff --git a/2-complexe/models.py b/2-complexe/models.py new file mode 100644 index 0000000000000000000000000000000000000000..f881ea148e304b73c4915d7ed1e3f1db0facde57 --- /dev/null +++ b/2-complexe/models.py @@ -0,0 +1,45 @@ +import numpy as np + + +class Complexe(): + + def __init__(self,re,im): + self.re = re + self.im = im + self.mod = np.sqrt(self.re**2+self.im**2) + self.arg=0.0 + self.calculer_arg() + + def calculer_arg(self): + if self.re==0: + self.arg = -np.pi + else: + self.arg = np.arctan(self.im/self.re) + + def tourner(self,theta): + if type(theta)==type(0.0): + self.arg+=theta + while self.arg < 0: + self.arg+=np.pi*2 + while self.arg >= np.pi*2: + self.arg-=np.pi*2 + + self.re=self.mod*np.cos(self.arg) + self.im=self.mod*np.sin(self.arg) + + def __str__(self): + string = "" + if self.re != 0: + string+=str(self.re) + if self.re !=0 and self.im!=0: + string+="+" + if self.im!=0: + string+=(str(self.im)+'i') + return string + + + +i=Complexe(0,1) +j=Complexe(-1/2,np.sqrt(3)/2) + +print(i) diff --git a/2-complexe/presentation.md b/2-complexe/presentation.md index bcf37527d8153af2c73486a6db97662ff0b878e3..90debde6863b7ba982f9d2ddddd327234f55e669 100644 --- a/2-complexe/presentation.md +++ b/2-complexe/presentation.md @@ -8,13 +8,16 @@ Nous allons prendre un objet beaucoup plus abstrait, mais que l'on connaît tous ### Quels attributs ? -- -- +- re +- im +- arg +- module ### Quelles méthodes ? -- -- +- ajouter un angle +- conjugué + ### Que va t'on faire dans le constructeur ? diff --git a/3-heritage/models.py b/3-heritage/models.py new file mode 100644 index 0000000000000000000000000000000000000000..0d6b7d47ad24ff8f0c122e780926b572ab60b529 --- /dev/null +++ b/3-heritage/models.py @@ -0,0 +1,44 @@ +class Meuble(): + + def __init__(self,x_pos,y_pos): + self.couleur = '0a0a2a' + self.x_pos = x_pos + self.y_pos = y_pos + self.forme = 'rectangle' + self.orientation = (1,0) #dx,dy + self.matiere = 'bois' + self.attributs_special_heritage() + + def attributs_special_heritage(self): + pass + + def tourner(self,new_orientation): + (dx,dy)=new_orientation + if dx in [-1,0,+1] and dy in [-1,0,+1] and dx*dy!=0: + self.orientation = (dx,dy) + + def bouger(self,x_pos,y_pos): + if type(x_pos)==type(0) and type(y_pos)==type(0): + self.x_pos = x_pos + self.y_pos = y_pos + else: + raise Exception ("Invalid coordinates") + +class Table(Meuble): + def attributs_special_heritage(self): + self.objets=[] + self.descente_n_plus_1() + + def descente_n_plus_1(self): + pass + +class Table_Ext(Table): + def descente_n_plus_1(self): + self.parasol=True + +class Lit(Meuble): + def attributs_special_heritage(self): + self.occupe=False + +table_ext=Table_Ext(5,5) +print(table_ext.parasol) \ No newline at end of file diff --git a/4-graphe/models.py b/4-graphe/models.py new file mode 100644 index 0000000000000000000000000000000000000000..39e74d33cdedf0adb70fbf7dd37f5b2747e227be --- /dev/null +++ b/4-graphe/models.py @@ -0,0 +1,28 @@ +import numpy as np + +class Graphe(): + + def __init__(self,n): + self.__n = n + self.__array = np.zeros((self.__n,self.__n)) + + def n(self): + return self.__n + + def set_n(self,n): + if n<self.__n: + self.__array = self.__array[:n,:n] + self.__n=n + + def set_link(self,i,j,value=1,sym=True): + try: + self.__array[i,j]=value + if sym: + self.__array[j,i]=value + except: + pass + + +g=Graphe(5) +g.set_n(3) +g.set_link(10,10) diff --git a/4-graphe/presentation.md b/4-graphe/presentation.md new file mode 100644 index 0000000000000000000000000000000000000000..d1d1889efbbd5b6cca4d325e1296c9ae99e919a4 --- /dev/null +++ b/4-graphe/presentation.md @@ -0,0 +1,32 @@ +# Une quatirème implémentation + +On va réaliser l'implémentation d'un second objet en Python, pour découvrir de nouvelles fonctionnalités, et de nouveaux raisonnement. + +### Choix de l'objet + +On prend encore un degrés d'abstraction supplémentaire : un **graphe**. De nouvelles questions se posent. + +### Une nouveauté : réfléchir à l'implémentation + +On doit maintenant réfléchir à **l'interface** et à **l'implémentation** : +- Liste d'adjacence +- Matrice d'adjacence +- ... + +### Quels attributs ? + +- Matrice d'adjacence -> privé +- taille du graphe-> privé +- + +### Quelles méthodes ? + +- is_connexe +- rajouter un lien(symétrique ou non) +- rupture d'un lien (symétrique ou non) +- modifier la taille + +### Que va t'on faire dans le constructeur ? + +- Initialiser les attributs +-