Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-Dahmane-lynda
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lynda Dahmane
AP-Dahmane-lynda
Commits
83730b5b
Commit
83730b5b
authored
1 year ago
by
Dahmane Lynda
Browse files
Options
Downloads
Patches
Plain Diff
etudiant.py
parent
3a2976df
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tp4/etudiants/etudiant.py
+100
-8
100 additions, 8 deletions
Tp4/etudiants/etudiant.py
with
100 additions
and
8 deletions
Tp4/etudiants/etudiant.py
100644 → 100755
+
100
−
8
View file @
83730b5b
...
@@ -41,15 +41,23 @@ class Etudiant:
...
@@ -41,15 +41,23 @@ class Etudiant:
$$$ isinstance(etu.naissance, Date)
$$$ isinstance(etu.naissance, Date)
True
True
"""
"""
def
__init__
(
self
,
nip
:
int
,
nom
:
str
,
prenom
:
str
,
def
__init__
(
self
,
nip
:
int
,
nom
:
str
,
prenom
:
str
,
naissance
:
Date
,
formation
:
str
,
groupe
:
str
):
naissance
:
Date
,
formation
:
str
,
groupe
:
str
):
"""
"""
initialise un nouvel étudiant à partir de son nip, son nom, son
initialis
-(
e un nouvel étudiant à partir de son nip, son nom, son
prénom, sa formation et son groupe.
prénom, sa formation et son groupe.
précondition : le nip, le nom et le prénom ne peuvent être nuls ou vides.
précondition : le nip, le nom et le prénom ne peuvent être nuls ou vides.
"""
"""
...
self
.
prenom
=
prenom
self
.
nom
=
nom
self
.
nip
=
nip
self
.
naissance
=
naissance
self
.
formation
=
formation
self
.
groupe
=
groupe
def
__eq__
(
self
,
other
)
->
bool
:
def
__eq__
(
self
,
other
)
->
bool
:
"""
"""
...
@@ -59,26 +67,110 @@ class Etudiant:
...
@@ -59,26 +67,110 @@ class Etudiant:
- même prénom que `self`,
- même prénom que `self`,
et False sinon.
et False sinon.
"""
"""
...
if
self
.
nip
==
other
.
nip
and
self
.
nom
==
other
.
nom
and
self
.
prenom
==
other
.
prenom
:
return
True
return
False
def
__lt__
(
self
,
other
)
->
bool
:
def
__lt__
(
self
,
other
)
->
bool
:
"""
"""
Renvoie True si self est né avant other
Renvoie True si self est né avant other
"""
"""
...
return
self
.
naissance
<
other
.
naissance
def
__str__
(
self
)
->
str
:
def
__str__
(
self
)
->
str
:
"""
"""
Renvoie une représentation textuelle de self.
Renvoie une représentation textuelle de self.
"""
"""
...
return
f
"
{
self
.
prenom
}
{
self
.
nom
}
"
def
__repr__
(
self
)
->
str
:
def
__repr__
(
self
)
->
str
:
"""
"""
Renvoie une représentation textuelle interne de self pour le shell.
Renvoie une représentation textuelle interne de self pour le shell.
"""
"""
...
x
=
self
.
nom
.
upper
()
return
f
"
{
self
.
nip
}
:
{
self
.
prenom
}
{
x
}
"
if
(
__name__
==
"
__main__
"
):
if
(
__name__
==
"
__main__
"
):
import
apl1test
import
apl1test
apl1test
.
testmod
(
'
etudiant.py
'
)
apl1test
.
testmod
(
'
etudiant.py
'
)
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
"""
if
isinstance
(
x
,
list
):
for
element
in
x
:
if
not
isinstance
(
element
,
Etudiant
):
return
False
return
True
return
False
#Q4:
NBRE_ETUDIANTS
=
len
(
L_ETUDIANTS
)
#Q5:
NIP
=
42320929
#Q6:
def
ensemble_des_formations
(
liste
:
list
[
Etudiant
])
->
Set
[
str
]:
"""
Renvoie un ensemble de chaînes de caractères donnant les formations
présentes dans les fiches d
'
étudiants
Précondition: liste ne contient que des fiches d
'
étudiants
Exemples:
$$$ ensemble_des_formations(COURTE_LISTE)
{
'
MI
'
,
'
PEIP
'
,
'
MIASHS
'
,
'
LICAM
'
}
$$$ ensemble_des_formations(COURTE_LISTE[0:2])
{
'
MI
'
,
'
MIASHS
'
}
"""
formations
=
Set
()
for
etudiant
in
liste
:
formations
.
add
(
etudiant
.
formation
)
return
formations
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment