Saya sedang berusaha membuat sistem tolong dibantu

Oleh agustinmiharja 52 1 pada Kamis, 26 Sep. 2024, 16:33:39


Kembali ke forum grup


Petunjuk Diskusi
Silahkan masuk untuk berdiskusi



class Participant:
    def __init__(self, name, age, weight_class):
        self.name = name
        self.age = age
        self.weight_class = weight_class

class Match:
    def __init__(self, participant1, participant2):
        self.participant1 = participant1
        self.participant2 = participant2
        self.winner = None

    def set_winner(self, winner):
        if winner in [self.participant1, self.participant2]:
            self.winner = winner
        else:
            raise ValueError("Winner must be one of the participants in the match")

class Tournament:
    def __init__(self):
        self.participants = []
        self.matches = []

    def add_participant(self, participant):
        self.participants.append(participant)

    def schedule_match(self, participant1, participant2):
        match = Match(participant1, participant2)
        self.matches.append(match)

    def record_match_result(self, match, winner):
        match.set_winner(winner)

    def get_match_results(self):
        results = []
        for match in self.matches:
            if match.winner:
                results.append(f"{match.participant1.name} vs {match.participant2.name} - Winner: {match.winner.name}")
            else:
                results.append(f"{match.participant1.name} vs {match.participant2.name} - No result yet")
        return results

# Contoh penggunaan
tournament = Tournament()

# Menambahkan peserta
participant1 = Participant("John Doe", 25, "Lightweight")
participant2 = Participant("Jane Smith", 22, "Lightweight")
participant3 = Participant("Mike Brown", 30, "Middleweight")

tournament.add_participant(participant1)
tournament.add_participant(participant2)
tournament.add_participant(participant3)

# Menjadwalkan pertandingan
tournament.schedule_match(participant1, participant2)

# Mencatat hasil pertandingan
tournament.record_match_result(tournament.matches[0], participant1)

# Menampilkan hasil pertandingan
for result in tournament.get_match_results():
    print(result)
1 jempol


Belum ada tanggapan