# your code goes here
class Student():
def __init__(self, name, conf):
self.name=name
for attr in ['exam_max', 'lab_max', 'lab_num', 'k']:
setattr(self, attr, conf.get(attr, None))
self.lab_ratings = [0]*self.lab_num
self.exam_rating = 0
def make_lab(self, m, n=None):
m = max( min(m, self.lab_max), 0 )
if n not in range(len(self.lab_ratings)):
n = self.lab_ratings.index(0)
self.lab_ratings[n] = m
self.output()
return self
def make_exam(self, m):
self.exam_rating = max( min(m, self.exam_max), 0 )
self.output()
return self
def is_certified(self):
max_rating = self.lab_max*self.lab_num + self.exam_max
rating = sum(self.lab_ratings) + self.exam_rating
return (rating, max_rating*self.k<=rating)
def output(self):
print self.name + ' labs: ' + ' '.join(str(r) for r in self.lab_ratings) + ' exam: ' + str(self.exam_rating)
def test():
conf = {
'exam_max': 30,
'lab_max': 7,
'lab_num': 10,
'k': 0.61,
}
oleg = Student('Oleg', conf)
oleg.make_lab(1) \
.make_lab(8,0) \
.make_lab(1) \
.make_lab(10,7) \
.make_lab(4,1) \
.make_lab(5) \
.make_lab(6.5) \
.make_exam(32)
sergiy = Student('Sergiy',
{
'exam_max': 10,
'lab_max': 12,
'lab_num': 5,
'k': 0.31,
})
sergiy.make_lab(10,1).make_lab(10,2).make_lab(10,3).make_exam(1000)
print(sergiy.is_certified())
print(oleg.is_certified()) # (59.5, False)
oleg.make_lab(7,1) # labs: 7 7 5 6.5 0 0 0 7 0 0, exam: 30
print(oleg.is_certified()) # (62.5, True)
test()
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCmNsYXNzIFN0dWRlbnQoKToKICAgIGRlZiBfX2luaXRfXyhzZWxmLCBuYW1lLCBjb25mKToKICAgICAgICBzZWxmLm5hbWU9bmFtZQogICAgICAgIGZvciBhdHRyIGluIFsnZXhhbV9tYXgnLCAnbGFiX21heCcsICdsYWJfbnVtJywgJ2snXToKICAgICAgICAJc2V0YXR0cihzZWxmLCBhdHRyLCBjb25mLmdldChhdHRyLCBOb25lKSkKICAgICAgICBzZWxmLmxhYl9yYXRpbmdzID0gWzBdKnNlbGYubGFiX251bQogICAgICAgIHNlbGYuZXhhbV9yYXRpbmcgPSAwCgogICAgZGVmIG1ha2VfbGFiKHNlbGYsIG0sIG49Tm9uZSk6CiAgICAgICAgbSA9IG1heCggbWluKG0sIHNlbGYubGFiX21heCksIDAgKSAgICAgICAgCiAgICAgICAgaWYgbiBub3QgaW4gcmFuZ2UobGVuKHNlbGYubGFiX3JhdGluZ3MpKToKICAgICAgICAgICAgbiA9IHNlbGYubGFiX3JhdGluZ3MuaW5kZXgoMCkgICAgCiAgICAgICAgc2VsZi5sYWJfcmF0aW5nc1tuXSA9IG0KICAgICAgICBzZWxmLm91dHB1dCgpCiAgICAgICAgcmV0dXJuIHNlbGYKCiAgICBkZWYgbWFrZV9leGFtKHNlbGYsIG0pOgogICAgICAgIHNlbGYuZXhhbV9yYXRpbmcgPSBtYXgoIG1pbihtLCBzZWxmLmV4YW1fbWF4KSwgMCApCiAgICAgICAgc2VsZi5vdXRwdXQoKQogICAgICAgIHJldHVybiBzZWxmCgogICAgZGVmIGlzX2NlcnRpZmllZChzZWxmKToKICAgICAgICBtYXhfcmF0aW5nID0gc2VsZi5sYWJfbWF4KnNlbGYubGFiX251bSArIHNlbGYuZXhhbV9tYXgKICAgICAgICByYXRpbmcgICAgID0gc3VtKHNlbGYubGFiX3JhdGluZ3MpICAgICArIHNlbGYuZXhhbV9yYXRpbmcKICAgICAgICByZXR1cm4gKHJhdGluZywgbWF4X3JhdGluZypzZWxmLms8PXJhdGluZykKICAgICAgICAKICAgIGRlZiBvdXRwdXQoc2VsZik6CiAgICAJcHJpbnQgc2VsZi5uYW1lICsgJyBsYWJzOiAnICsgJyAnLmpvaW4oc3RyKHIpIGZvciByIGluIHNlbGYubGFiX3JhdGluZ3MpICsgJyBleGFtOiAnICsgc3RyKHNlbGYuZXhhbV9yYXRpbmcpCgpkZWYgdGVzdCgpOgogICAgY29uZiA9IHsKICAgICdleGFtX21heCc6IDMwLAogICAgJ2xhYl9t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