Skip to content
Snippets Groups Projects
Commit 0bcb1fa5 authored by Angy Wallot's avatar Angy Wallot
Browse files

tp.4

parent 023fb434
No related branches found
No related tags found
No related merge requests found
,angy.wallot.etu,118p26,07.02.2024 11:36,file:///home/l1/angy.wallot.etu/.config/libreoffice/4;
\ No newline at end of file
...@@ -87,69 +87,6 @@ class Etudiant: ...@@ -87,69 +87,6 @@ class Etudiant:
def charge_fichier_etudiants(fname: str) -> list[Etudiant]:
"""
Renvoie la liste des étudiants présents dans le fichier dont
le nom est donné en paramètre.
précondition: le fichier est du bon format.
"""
res = []
with open(fname, 'r') as fin:
fin.readline()
ligne = fin.readline()
while ligne != '':
nip, nom, prenom, naissance, formation, groupe = ligne.strip().split(';')
y, m, d = naissance.split('-')
date_naiss = Date(int(d.lstrip('0')), int(m.lstrip('0')), int(y))
res.append(Etudiant(nip, nom, prenom, date_naiss, formation, groupe))
ligne = fin.readline()
return res
L_ETUDIANTS = charge_fichier_etudiants("etudiants.csv")
COURTE_LISTE = L_ETUDIANTS[:10]
def est_liste_d_etudiants(x) -> bool:
"""
Renvoie True si ``x`` est une liste de d'étudiant, False dans le cas contraire.
Précondition: aucune
Exemples:
$$$ est_liste_d_etudiants(COURTE_LISTE)
True
$$$ est_liste_d_etudiants("Timoleon")
False
$$$ est_liste_d_etudiants([('12345678', 'Calbuth', 'Raymond', 'Danse', '12') ])
False
"""
res = isinstance(x, list)
if res == True:
for el in x:
res = isinstance(el, Etudiant)
return res
NBRE_ETUDIANTS = len(L_ETUDIANTS)
NIP ="42312037"
def s(n):
"""à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$ s(49423558)
'Marcel Rocher'
$$$ s(49452026)
'Laetitia Sanchez'
$$$ s(NIP)
'non'
"""
for el in L_ETUDIANTS:
if el.nip == str(n):
return el.prenom + " " +el.nom
return "non"
if (__name__ == "__main__"): if (__name__ == "__main__"):
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#gestion_promo_etudiants #gestion_promo_etudiants
#07/02/24 #07/02/24
from date import Date
from etudiant import Etudiant
def pour_tous(seq_bool: bool) -> bool: def pour_tous(seq_bool: bool) -> bool:
""" """
Renvoie True ssi `seq_bool` ne contient pas False Renvoie True ssi `seq_bool` ne contient pas False
...@@ -38,3 +41,75 @@ def il_existe(seq_bool: bool) -> bool: ...@@ -38,3 +41,75 @@ def il_existe(seq_bool: bool) -> bool:
if el == True: if el == True:
return el return el
return False return False
def charge_fichier_etudiants(fname: str) -> list[Etudiant]:
"""
Renvoie la liste des étudiants présents dans le fichier dont
le nom est donné en paramètre.
précondition: le fichier est du bon format.
"""
res = []
with open(fname, 'r') as fin:
fin.readline()
ligne = fin.readline()
while ligne != '':
nip, nom, prenom, naissance, formation, groupe = ligne.strip().split(';')
y, m, d = naissance.split('-')
date_naiss = Date(int(d.lstrip('0')), int(m.lstrip('0')), int(y))
res.append(Etudiant(nip, nom, prenom, date_naiss, formation, groupe))
ligne = fin.readline()
return res
L_ETUDIANTS = charge_fichier_etudiants("etudiants.csv")
COURTE_LISTE = L_ETUDIANTS[:10]
def est_liste_d_etudiants(x) -> bool:
"""
Renvoie True si ``x`` est une liste de d'étudiant, False dans le cas contraire.
Précondition: aucune
Exemples:
$$$ est_liste_d_etudiants(COURTE_LISTE)
True
$$$ est_liste_d_etudiants("Timoleon")
False
$$$ est_liste_d_etudiants([('12345678', 'Calbuth', 'Raymond', 'Danse', '12') ])
False
"""
res = isinstance(x, list)
if res == True:
for el in x:
res = isinstance(el, Etudiant)
return res
NBRE_ETUDIANTS = len(L_ETUDIANTS)
NIP ="42312037"
def s(n):
"""à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$ s(49423558)
'Marcel Rocher'
$$$ s(49452026)
'Laetitia Sanchez'
$$$ s(NIP)
'non'
"""
for el in L_ETUDIANTS:
if el.nip == str(n):
return el.prenom + " " +el.nom
return "non"
def li(l):
res = []
for i in range(len(l)):
s = f"{l[i].naissance.jour}-{l[i].naissance.mois}-{l[i].naissance.annee}"
if s < 2-2-2003:
res.append(l[i].prenom)
return res
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment