Respuesta :
Answer:
See explaination
Explanation:
class Player:
def __init__(self, name, points):
self.name = name
self.points = points
def __lt__(self, others):
return self.name < other.name
def __str__(self):
return f"player('{self.name}', {self.points})"
def __repr__(self):
return self.__str__()
def __eq__(self, other):
return self.name == other.name and self.points == other.points
class Team:
def __init__(self, name, players=None):
self.name = name
self.players = [] if players is None else players
def add_player(self, name, points):
player = player(name, points)
self.players.append(player)
def __str__(self):
return f"Team('{self.name}', {self.players})"
def __repr__(self):
return self.__str__()
def verify_players(correct_players, players_selected):
if players_selected is None:
return False
if len(correct_players) != len(players_selected):
return False
for ind in range(len(correct_players)):
if correct_players[ind] != players_selected[ind]:
return False
return True
def find_above_avg_players(team):
# find the sum of the points of all players
sum_points = 0
for player in team.players:
sum_points += player.points
# find the average of the points
average = sum_points / len(team.players)
# an empty list to store the above average players
above_average_players = []
for player in team.players:
# append the player to the list if the points is greater than average
if(player.points > average):
above_average_players.append(player)
return above_average_players
# Testing
team = Team('Ny Giants', [Player('B', 8), Player('D', 13), Player('A', 1), Player('C', 2)])
print(find_above_avg_players(team))
# Testing
team1 = Team('Atlana Braves', [Player('F', 14), Player('B', 12), Player('E', 10), Player('D', 0), Player('H', 1), Player('A', 19), Player('G', 3), Player('I', 2), Player('C', 2)])
print(find_above_avg_players(team1))