Skip to content

Commit

Permalink
Restructuring Exercise 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Godwin-Jules committed Aug 31, 2024
1 parent d520214 commit 583d8a4
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
61 changes: 61 additions & 0 deletions activite03/exercice1/Complexe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
"""
from math import sqrt


class Complexe:

# Le constructeur
def __init__(self, a=0, b=0):
self.__a = a
self.__b = b

# Les accesseurs
def getA(self):
return self.__a

def getB(self):
return self.__b

def setA(self, a):
self.__a = a

def setB(self, b):
self.__b = b

# La méthode qui permet de faire afficher un nombre complexe
def __str__(self):
a = self.getA()
b = self.getB()
if not(a != 0 or (a == 0 and b == 0)):
a = ""
return f"{a}{"+" if b > 0 else ""}{b if b not in {-1, 0, 1} else ""}{"i" if b != 0 else ""}"

# La méthode qui retourne la somme de deux nombre complexes
def ajouter(self, complex):
return Complexe(self.getA() + complex.getA(), self.getB() + complex.getB())

# La méthode qui retourne le produit de deux nombres complexes
def produit(self, complex):
a = self.getA()*complex.getA() - self.getB()*complex.getB()
b = self.getA()*complex.getB() + self.getB()*complex.getA()
return Complexe(a, b)

# La méthode qui retourne le conjugué d'un nombre complexe
def conjugue(self):
return Complexe(self.getA(), - self.getB())

# La méthode qui calcule le module d'un nombre complexe
def module(self):
return f"{sqrt(self.getA()**2 + self.getB()**2):.2f}"

# La méthode qui retourne le carré d'un nombre complexe
def carre(self):
a = self.getA()**2 - self.getB()**2
b = 2 * self.getA() * self.getB()
return Complexe(a, b)

# La méthode qui compare deux nombre complexes
def comparer(self, complex):
return True if self.getA() == complex.getA() and self.getB() == complex.getB() else False
7 changes: 5 additions & 2 deletions activite03/exercice1.py → activite03/exercice1/exercice1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ def setB(self, b):

# La méthode qui permet de faire afficher un nombre complexe
def __str__(self):
a = self.getA()
b = self.getB()
return f"{self.getA()} {"+" if b > 0 else ""}{b if b not in {-1, 0, 1} else ""}{"i" if b != 0 else ""}"
if not(a != 0 or (a == 0 and b == 0)):
a = ""
return f"{a}{"+" if b > 0 else ""}{b if b not in {-1, 0, 1} else ""}{"i" if b != 0 else ""}"

# La méthode qui retourne la somme de deux nombre complexes
def ajouter(self, complex):
Expand All @@ -42,7 +45,7 @@ def conjugue(self):

# La méthode qui calcule le module d'un nombre complexe
def module(self):
return sqrt(self.getA()**2 + self.getB()**2)
return f"{sqrt(self.getA()**2 + self.getB()**2):.2f}"

# La méthode qui retourne le carré d'un nombre complexe
def carre(self):
Expand Down
20 changes: 20 additions & 0 deletions activite03/exercice1/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from Complexe import Complexe


# Application de l'exercice 1
nb1 = Complexe(1, -1)
nb2 = Complexe(2, 4)

somme = nb1.ajouter(nb1)
produit = nb1.produit(nb2)
conjugue = nb1.conjugue()
module = nb1.module()
carre = nb1.carre()

print(somme)
print(produit)
print(conjugue)
print(module)
print(carre)
print(nb1.comparer(nb2))
print(Complexe())
8 changes: 6 additions & 2 deletions activite03/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from exercice1 import Complexe
from exercice1.exercice1 import Complexe
from exercice2.exercice2 import *
from exercice3.exercice3 import *
from exercice4.exercice4 import *



# Application de l'exercice 1
print("\n=================== APPLICATION DE L'EXERCICE 1 ===================\n\n")
nb1 = Complexe(1, -1)
nb2 = Complexe(2, 4)

Expand All @@ -25,6 +26,7 @@


# Application de l'exercice 2
print("\n\n\n=================== APPLICATION DE L'EXERCICE 2 ===================\n\n")
com6 = Commercial("TREVOR", "Albertine", 180_000)
emp1 = Employee("KOKOU", "Komi", 245)
emp2 = Employee("AKAKPO", "Komla", 305)
Expand Down Expand Up @@ -67,6 +69,7 @@


# Application de l'exercice 3
print("\n\n\n=================== APPLICATION DE L'EXERCICE 3 ===================\n\n")
livre1 = Livre("Automate the Boring Stuff with Python", "Al Sweigart", "978-1-59327-992-9")
livre2 = Livre("L'art de négocier", "Dag Heward-Mills", "978-2-212-54434-3")
livre3 = Livre("English Grammar in Use", "Raymond Murphy", "978-1-108-58662-7")
Expand All @@ -88,6 +91,7 @@


# Application de l'exercice 4
print("\n\n\n=================== APPLICATION DE L'EXERCICE 4 ===================\n\n")
pk1 = Pokemon("pokemon 1")
pk2 = PokemonFeu("PokemonFeu 1")
pk3 = PokemonFeu("PokemonFeu 2")
Expand Down Expand Up @@ -118,7 +122,7 @@
pk4.attaquer(pk3) # pk3 = 65, pk4 = 90

# Afffichage après attaques
print("\nEtat des pokémons après les attaques")
print("Etat des pokémons après les attaques")
pk1.afficher()
pk2.afficher()
pk3.afficher()
Expand Down

0 comments on commit 583d8a4

Please sign in to comment.