The Python code to solve the problems based on the provided specifications using Python and have the necessary libraries inside is shown below
import matplotlib.pyplot as plt
def process_season(season_goals, season_results):
total_matches = len(season_results)
wins = season_results.count('W')
losses = season_results.count('L')
draws = season_results.count('D')
one_goal_wins = sum(1 for goals in season_goals if goals == 1)
points = 3 * wins + draws
print("Total matches played:", total_matches)
print("Wins:", wins)
print("Losses:", losses)
print("Draws:", draws)
print("Wins with only one goal:", one_goal_wins)
print("Points:", points)
print()
return total_matches, wins, losses, draws, one_goal_wins, points
def analyze_seasons(data):
min_wins_season = min(data, key=lambda x: x[1])
max_goals_season = max(data, key=lambda x: sum(x[0]))
print("Season with the fewest wins:", min_wins_season[0])
print("Season with the most goals:", max_goals_season[0])
print()
def visualize_season(season_goals, season_results):
colors = {'W': 'green', 'L': 'red', 'D': 'gray'}
plt.figure(figsize=(10, 6))
plt.scatter(range(1, len(season_goals) + 1), season_goals, c=[colors[result] for result in season_results])
plt.title('Goals Record for a Season')
plt.xlabel('Match Number')
plt.ylabel('Goals Scored')
plt.legend(['Win', 'Loss', 'Draw'], loc='upper right')
plt.show()
def main():
with open('hotspurs.txt') as file:
data = file.read().splitlines()
season_data = [data[i:i+2] for i in range(0, len(data), 2)]
for season in season_data:
season_goals = list(map(int, season[0].split()[1:]))
season_results = season[1].split()[1:]
total, wins, losses, draws, one_goal_wins, points = process_season(season_goals, season_results)
visualize_season(season_goals, season_results)
analyze_seasons([(list(map(int, season[0].split()[1:])), season[1].split()[1:]) for season in season_data])
if __name__ == "__main__":
main()