fork(2) download
  1. # your code goes here
  2. class Student():
  3. def __init__(self, name, conf):
  4. self.name=name
  5. for attr in ['exam_max', 'lab_max', 'lab_num', 'k']:
  6. setattr(self, attr, conf.get(attr, None))
  7. self.lab_ratings = [0]*self.lab_num
  8. self.exam_rating = 0
  9.  
  10. def make_lab(self, m, n=None):
  11. m = max( min(m, self.lab_max), 0 )
  12. if n not in range(len(self.lab_ratings)):
  13. n = self.lab_ratings.index(0)
  14. self.lab_ratings[n] = m
  15. self.output()
  16. return self
  17.  
  18. def make_exam(self, m):
  19. self.exam_rating = max( min(m, self.exam_max), 0 )
  20. self.output()
  21. return self
  22.  
  23. def is_certified(self):
  24. max_rating = self.lab_max*self.lab_num + self.exam_max
  25. rating = sum(self.lab_ratings) + self.exam_rating
  26. return (rating, max_rating*self.k<=rating)
  27.  
  28. def output(self):
  29. print self.name + ' labs: ' + ' '.join(str(r) for r in self.lab_ratings) + ' exam: ' + str(self.exam_rating)
  30.  
  31. def test():
  32. conf = {
  33. 'exam_max': 30,
  34. 'lab_max': 7,
  35. 'lab_num': 10,
  36. 'k': 0.61,
  37. }
  38. oleg = Student('Oleg', conf)
  39. oleg.make_lab(1) \
  40. .make_lab(8,0) \
  41. .make_lab(1) \
  42. .make_lab(10,7) \
  43. .make_lab(4,1) \
  44. .make_lab(5) \
  45. .make_lab(6.5) \
  46. .make_exam(32)
  47. sergiy = Student('Sergiy',
  48. {
  49. 'exam_max': 10,
  50. 'lab_max': 12,
  51. 'lab_num': 5,
  52. 'k': 0.31,
  53. })
  54. sergiy.make_lab(10,1).make_lab(10,2).make_lab(10,3).make_exam(1000)
  55. print(sergiy.is_certified())
  56. print(oleg.is_certified()) # (59.5, False)
  57. oleg.make_lab(7,1) # labs: 7 7 5 6.5 0 0 0 7 0 0, exam: 30
  58. print(oleg.is_certified()) # (62.5, True)
  59.  
  60. test()
  61.  
Success #stdin #stdout 0s 9024KB
stdin
Standard input is empty
stdout
Oleg labs: 1 0 0 0 0 0 0 0 0 0 exam: 0
Oleg labs: 7 0 0 0 0 0 0 0 0 0 exam: 0
Oleg labs: 7 1 0 0 0 0 0 0 0 0 exam: 0
Oleg labs: 7 1 0 0 0 0 0 7 0 0 exam: 0
Oleg labs: 7 4 0 0 0 0 0 7 0 0 exam: 0
Oleg labs: 7 4 5 0 0 0 0 7 0 0 exam: 0
Oleg labs: 7 4 5 6.5 0 0 0 7 0 0 exam: 0
Oleg labs: 7 4 5 6.5 0 0 0 7 0 0 exam: 30
Sergiy labs: 0 10 0 0 0 exam: 0
Sergiy labs: 0 10 10 0 0 exam: 0
Sergiy labs: 0 10 10 10 0 exam: 0
Sergiy labs: 0 10 10 10 0 exam: 10
(40, True)
(59.5, False)
Oleg labs: 7 7 5 6.5 0 0 0 7 0 0 exam: 30
(62.5, True)