@@ -727,6 +727,11 @@ Implement a simple system for managing a sports league, where each team has seve
727727``` {pyodide-python}
728728class Player:
729729
730+ def __init__(self, name, position, performance_score):
731+ self.name = name
732+ self.position = position
733+ class Player:
734+
730735 def __init__(self, name, position, performance_score):
731736 self.name = name
732737 self.position = position
@@ -739,18 +744,21 @@ class Team:
739744 self.players = []
740745
741746def best_player(team):
742- highest_score = max(p.performance_score for p in team.players)
743- best_player = [p.name for p in team.players if p.performance_score == highest_score]
744- return best_player
745-
747+ return max(team.players, key=lambda player: player.performance_score)
748+
749+
746750player1 = Player("Alice", "Forward", 8.5)
747751player2 = Player("Bob", "Guard", 9.0)
748- player3 = Player("Charlie", "Center", 9 .0)
752+ player3 = Player("Charlie", "Center", 7 .0)
749753
750754teamA = Team("Team A")
751755teamA.players.extend([player1, player2, player3])
752756
753- print(best_player(teamA))
757+ # Find the best player
758+ # the variable star is an object of the Player class
759+ star = best_player(teamA)
760+ print(f"The best player in {teamA.team_name} is {star.name}.")
761+ print(f"He/She is a {star.position} and his/her score is {star.performance_score}.")
754762```
755763---
756764
0 commit comments