Last active
May 1, 2016 13:12
-
-
Save fxg42/58a391186a763c45020d2c0bea4e2d37 to your computer and use it in GitHub Desktop.
Final INF1256
This file contains hidden or 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
def somme(liste_nombres): | |
position = 0 | |
longueur = len(liste_nombres) | |
somme = 0 | |
while position < longueur: | |
somme += liste_nombres[position] | |
position += 1 | |
return somme | |
print somme([ 1, 2, 3, 2, 1 ]) |
This file contains hidden or 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
def frequence(liste_lettres): | |
frequences = { } | |
for lettre in liste_lettres: | |
if lettre in frequences: | |
frequences[lettre] = frequences[lettre] + 1 | |
else: | |
frequences[lettre] = 1 | |
return frequences | |
print frequence(['a', 'b', 'a', 'b', 'c']) |
This file contains hidden or 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
def moyenne_par_jour(liste_semaines): | |
cumuls = { 'lu':0, 'ma':0, 'me':0, 'je':0, 've':0 } | |
for semaine in liste_semaines: | |
for jour in semaine: | |
cumuls[jour] += semaine[jour] | |
moyennes = { 'lu':0, 'ma':0, 'me':0, 'je':0, 've':0 } | |
for jour in cumuls: | |
moyennes[jour] = cumuls[jour]/len(liste_semaines) | |
return moyennes | |
liste_semaines = [ | |
{ 'lu':8.0, 'ma':6.0, 'me':8.0, 'je':8.0, 've':4.0 }, | |
{ 'lu':7.0, 'ma':5.0, 'me':8.0, 'je':7.0, 've':5.0 } | |
] | |
print moyenne_par_jour(liste_semaines) |
This file contains hidden or 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
class Etudiante(object): | |
def __init__(self, code_permanent): | |
self.code_permanent = code_permanent | |
self.notes = [ ] | |
class Cours(object): | |
def __init__(self, sigle): | |
self.sigle = sigle | |
class Note(object): | |
def __init__(self, valeur, cours): | |
self.valeur = valeur | |
self.cours = cours | |
class NoteLettre(Note): | |
pass | |
class NotePourcentage(Note): | |
pass | |
alice = Etudiante('ABCD12345678') | |
assert alice.code_permanent == 'ABCD12345678' | |
programmation1 = Cours('INF1256') | |
assert programmation1.sigle == 'INF1256' | |
note_alice_programmation1 = NoteLettre('A+', programmation1) | |
alice.notes.append(note_alice_programmation1) | |
assert alice.notes[0].valeur == 'A+' | |
assert alice.notes[0].cours.sigle == 'INF1256' |
This file contains hidden or 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
class Abonnee(object): | |
def __init__(self): | |
self.reservations = [ ] | |
self.emprunts = [ ] | |
self.politique_emprunt = PolitiqueEmprunt(25) | |
def emprunter(self, un_exemplaire): | |
if self.politique_emprunt.est_respectee(self): | |
self.emprunts.append(Emprunt(un_exemplaire)) | |
class Reservation(object): | |
def __init__(self, livre): | |
self.livre = livre | |
class Emprunt(object): | |
def __init__(self, exemplaire): | |
self.exemplaire = exemplaire | |
class Livre(object): | |
def __init__(self, isbn, titre): | |
self.isbn = isbn | |
self.titre = titre | |
self.exemplaires = [ ] | |
class Exemplaire(object): | |
pass | |
class PolitiqueEmprunt(object): | |
def __init__(self, limite): | |
self.limite = limite | |
def est_respectee(self, abonnee): | |
return len(abonnee.emprunts) < self.limite |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment