Last active
May 11, 2021 11:07
-
-
Save zulzeen/ad6f5a6a4738705adcfbefac3e792991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
from dataclasses import dataclass | |
from abc import ABC, abstractmethod | |
from typing import List | |
class Personne: | |
def __init__(self, nom, prenom): | |
self._nom = nom | |
self._prenom = prenom | |
@property | |
def nom(self): | |
return self._nom | |
@property | |
def prenom(self): | |
return self._prenom | |
@property | |
def mail(self): | |
try: | |
mail = self._mail | |
except AttributeError: | |
mail = f"{self.prenom.lower()}.{self.nom.lower()}@elementary.school" | |
return mail | |
@mail.setter | |
def mail(self, mail): | |
self._mail = mail | |
@property | |
def nom_complet(self): | |
return f"{self.prenom} {self.nom}" | |
class Etudiant(ABC, Personne): | |
def __init__(self, nom, prenom, majeure): | |
super().__init__(nom, prenom) | |
self.majeure = majeure | |
def save(self): | |
with open(os.path.join(os.path.dirname(__file__), 'listing.csv'), 'a+') as output: | |
output.write(f"{self.nom}, {self.prenom}, {self.majeure}, {';'.join(self.apprentissage_valides())}\n") | |
@abstractmethod | |
def apprentissage_valides(self): | |
pass | |
def __repr__(self): | |
return f"{self.nom_complet} ({self.majeure.nom})" | |
@dataclass | |
class Matiere: | |
nom: str | |
competences: List[str] | |
moyenne_a_obtenir: int | |
@dataclass | |
class Majeure: | |
nom: str | |
matieres: List[Matiere] | |
def ajouter_matiere(self, matiere): | |
self.matieres.append(matiere) | |
def recuperer_matiere(self, nom_matiere): | |
for matiere in self.matieres: | |
if matiere.nom == nom_matiere: | |
return matiere | |
message = f"{nom_matiere} n'est pas une matière, les matières disponibles sont: " | |
message += f"{','.join([matiere.nom for matiere in self.matieres])}" | |
raise KeyError(message) | |
class EtudiantWind(Etudiant): | |
def __init__(self, nom, prenom, majeure): | |
super().__init__(nom, prenom, majeure) | |
self.competences = set() | |
def valider_competence(self, competence): | |
for matiere in self.majeure.matieres: | |
if competence in matiere.competences: | |
self.competences.add(competence) | |
def apprentissage_valides(self): | |
return list(self.competences) | |
class EtudiantFire(Etudiant): | |
def __init__(self, nom, prenom, majeure): | |
super().__init__(nom, prenom, majeure) | |
self.notes = {} | |
def noter_matiere(self, nom_matiere, note): | |
if self.majeure.recuperer_matiere(nom_matiere): | |
self.notes[nom_matiere] = note | |
def apprentissage_valides(self): | |
return [ matiere for matiere in self.notes.keys() | |
if self.notes[matiere] > self.majeure.recuperer_matiere(matiere).moyenne_a_obtenir ] | |
if __name__ == "__main__": | |
mathematiques = Matiere('Mathématiques', ['Compter'], 12) | |
feu = Majeure('Fire', [mathematiques]) | |
vent = Majeure('Wind', [mathematiques]) | |
etudiant_feu, etudiant_vent = etudiants = [EtudiantFire('Cage', 'Nicolas', feu), EtudiantWind('Pitt', 'Brad', vent)] | |
etudiant_feu.noter_matiere('Mathématiques', 13) | |
etudiant_vent.valider_competence('Compter') | |
print("Apprentissages validés") | |
print("\n".join([": ".join((str(etudiant), | |
",".join(etudiant.apprentissage_valides()))) | |
for etudiant in etudiants])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment