17.12.2012 Views

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Principaux modules, partie 2<br />

CHAPITRE 9<br />

>>> ok_work = ['Bonne première partie mais soignez la présentation',<br />

... 'Petites erreurs, dommage !',<br />

... 'Des progrès']<br />

>>> class Work(object):<br />

... def __init__(self, student):<br />

... self.student = student<br />

... self.auto_corrector()<br />

... def auto_corrector(self):<br />

... self.note = random.randint(1, 20)<br />

... if self.note < 8:<br />

... self.appreciation = random.choice(bad_work)<br />

... elif self.note < 14:<br />

... self.appreciation = random.choice(ok_work)<br />

... else:<br />

... self.appreciation = random.choice(good_work)<br />

... def __str__(self):<br />

... return '%s: %s, %s' %(self.student, self.note,<br />

self.appreciation)<br />

...<br />

>>> students = ['Bernard', 'Robert', 'René', 'Gaston',<br />

... 'Églantine', 'Aimé', 'Robertine']<br />

>>> works = [Work(student) for student in students]<br />

>>> for work in works:<br />

... print work<br />

...<br />

Bernard: 20, Très bonne analyse<br />

Robert: 13, Des progrès<br />

René: 1, Vous filez un mauvais coton<br />

Gaston: 13, Des progrès<br />

Églantine: 20, Très bonne analyse<br />

Aimé: 2, J'ai gratté la copie pour mettre des points<br />

Robertine: 11, Petites erreurs, dommage !<br />

En un mot...<br />

Les modules présentés dans ce chapitre fournissent des outils de programmation qui<br />

peuvent être utilisés dans des applications variées.<br />

Le chapitre 10 complète cette collection par la présentation de quelques modules<br />

additionnels : itertools, re, Tkinter et lib2to3.<br />

309

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!