class Klasemen:
def __init__(self, klub):
self.klasemen = {}
for i in klub:
self.klasemen[i] = 0
def catatPermainan(self, klubKandang, klubTandang, skor):
skor = skor.split(':')
if int(skor[0]) > int(skor[1]):
self.klasemen[klubKandang] += 3
elif int(skor[0]) < int(skor[1]):
self.klasemen[klubTandang] += 3
else:
self.klasemen[klubKandang] += 1
self.klasemen[klubTandang] += 1
self.klasemen = dict(sorted(self.klasemen.items(), key=lambda x: x[1], reverse=True))
def cetakKlasemen(self):
return self.klasemen
def ambilPeringkat(self, nomorPeringkat):
return list(self.klasemen.keys())[nomorPeringkat-1]
klasemen = Klasemen(['Liverpool', 'Chelsea', 'Arsenal'])
klasemen.catatPermainan('Arsenal', 'Liverpool', '2:1')
klasemen.catatPermainan('Arsenal', 'Chelsea', '1:1')
klasemen.catatPermainan('Chelsea', 'Arsenal', '0:3')
klasemen.catatPermainan('Chelsea', 'Liverpool', '3:2')
klasemen.catatPermainan('Liverpool', 'Arsenal', '2:2')
klasemen.catatPermainan('Liverpool', 'Chelsea', '0:0')
print(klasemen.cetakKlasemen())
print(klasemen.ambilPeringkat(2))
Y2xhc3MgS2xhc2VtZW46CiAgICBkZWYgX19pbml0X18oc2VsZiwga2x1Yik6CiAgICAgICAgc2VsZi5rbGFzZW1lbiA9IHt9CiAgICAgICAgZm9yIGkgaW4ga2x1YjoKICAgICAgICAgICAgc2VsZi5rbGFzZW1lbltpXSA9IDAKCiAgICBkZWYgY2F0YXRQZXJtYWluYW4oc2VsZiwga2x1YkthbmRhbmcsIGtsdWJUYW5kYW5nLCBza29yKToKICAgICAgICBza29yID0gc2tvci5zcGxpdCgnOicpCiAgICAgICAgaWYgaW50KHNrb3JbMF0pID4gaW50KHNrb3JbMV0pOgogICAgICAgICAgICBzZWxmLmtsYXNlbWVuW2tsdWJLYW5kYW5nXSArPSAzCiAgICAgICAgZWxpZiBpbnQoc2tvclswXSkgPCBpbnQoc2tvclsxXSk6CiAgICAgICAgICAgIHNlbGYua2xhc2VtZW5ba2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