premiere version stable du cours de poo

This commit is contained in:
gwen
2017-10-02 09:10:51 +02:00
committed by Benjamin Bohard
parent 051c60fed6
commit 14212752fc
20 changed files with 1016 additions and 406 deletions

View File

@ -0,0 +1,34 @@
# coding: utf-8
# object oriented version
class Student:
def __init__(self, name, birth_date):
self.name = name
self.birth_date = birth_date
self.classroom = None
def move(self, classroom):
self.classroom = classroom
student1 = Student(name='pierre', birth_date=None)
student2 = Student(name='paul', birth_date=None)
student3 = Student(name='jacques', birth_date=None)
class Principal:
classrooms_registry = dict(pierre='4eme3', paul='4eme2', jacques='4eme5')
students = [student1, student2, student3]
def move_students(self):
for student in self.students:
classroom = self.classrooms_registry[student.name]
student.move(classroom)
for student in self.students:
print "The student: {} is assigned to the class {}".format(student.name, student.classroom)
principal = Principal()
if __name__ == "__main__":
principal.move_students()

View File

@ -0,0 +1,23 @@
# coding: utf-8
# procedural version
student1 = dict(name='pierre', birth_date=None)
student2 = dict(name='paul', birth_date=None)
student3 = dict(name='jacques', birth_date=None)
classrooms_registry = dict(pierre='4eme3', paul='4eme2', jacques='4eme5')
students = [student1, student2, student3]
def move_students():
for student in students:
classroom = classrooms_registry[student['name']]
student['classroom'] = classroom
for student in students:
print "The student: {} is assigned to the class {}".format(student['name'], student['classroom'])
if __name__ == "__main__":
move_students()