# Python 3
class Klasemen():
def __init__(self, daftar_klub: list[str]):
# init klasemen klub
self.daftar_klub = {klub: 0 for klub in daftar_klub}
def catatPermainan(self, klubKandang: str, klubTandang: str, skor: str):
extract_skor = skor.split(":")
# ganti tipe data
skorKandang = int(extract_skor[0])
skorTandang = int(extract_skor[1])
if(skorKandang > skorTandang):
# klub kandang menang
self.daftar_klub[klubKandang] += 3
elif(skorKandang < skorTandang):
# klub tandang menang
self.daftar_klub[klubTandang] += 3
else:
# seri
self.daftar_klub[klubKandang] += 1
self.daftar_klub[klubTandang] += 1
# urutkan klasemen berdasarkan poin klub secara descending
self.daftar_klub = dict(sorted(self.daftar_klub.items(), key=lambda x: x[1], reverse=True))
def cetakKlasemen(self):
print(list(self.daftar_klub.items()))
def ambilPeringkat(self, noPeringkat: int):
print(list(self.daftar_klub.items())[noPeringkat-1][0])
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')
klasemen.cetakKlasemen()
klasemen.ambilPeringkat(2)
IyBQeXRob24gMwoKY2xhc3MgS2xhc2VtZW4oKToKICAgIGRlZiBfX2luaXRfXyhzZWxmLCBkYWZ0YXJfa2x1YjogbGlzdFtzdHJdKToKICAgICAgICAjIGluaXQga2xhc2VtZW4ga2x1YgogICAgICAgIHNlbGYuZGFmdGFyX2tsdWIgPSB7a2x1YjogMCBmb3Iga2x1YiBpbiBkYWZ0YXJfa2x1Yn0KCiAgICBkZWYgY2F0YXRQZXJtYWluYW4oc2VsZiwga2x1YkthbmRhbmc6IHN0ciwga2x1YlRhbmRhbmc6IHN0ciwgc2tvcjogc3RyKToKICAgICAgICBleHRyYW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