""" Felix Muzny DS 2000 Lecture 9 October 8, 2024 Data file (first 12 Boston Fleet games of the PWHL regular season): Opponent names (comma separated) Boston scores (comma separated) Opponent scores (comma separated) Goals for today’s code: - use some already implemented functions - write some function documentation - plot some lists """ import matplotlib.pyplot as plt FILENAME = "boston_fleet.csv" def celebrate(points1, points2): """ If the first team has more points, print a congratulatory message; otherwise dissapointment or a message about tying :param points1: int score for first team :param points2: int score for the second team :return: none/nothing """ if points1 > points2: print("WOOOOOHOOOOOO!") elif points2 > points1: print("sadness :(") else: print("tied!") def make_int_list(original_list): """ Make a new list of integer versions of the original list :param original_list: list of strings to convert to ints :return: list of ints """ # original_list = first value passed to the function new_ls = [] for value in original_list: # value will be an element from the original list # the job of this function is to change a list # into a list of integers new_ls.append(int(value)) return new_ls # Added after lecture for more plotting examples! def plot_goals(goals1, goals2): # make a list of x values game_nums = [] for i in range(len(goals1)): game_nums.append(i) # be sure to include label! plt.plot(game_nums, goals1, "*", color="green", label="first team goals") plt.plot(game_nums, goals2, "s", color="blue", label="second team goals") # make sure to include a legend! plt.legend() # use a better title than this :) plt.title("scores") plt.xlabel("game number") plt.ylabel("goals") plt.show() def main(): print("lec 9 - pwhl") with open(FILENAME, "r") as file: # my file will always just have three lines teams = file.readline().strip().split(",") boston = file.readline().split(",") opponent = file.readline().split(",") # check to make sure they are the same length print("teams:", teams) # lists are currently lists of strings print("boston:", boston) print("opponent:", opponent) # TODO: use make_int_list to update our lists # boston_ints = make_int_list([2, 3, 3, .....]) boston_ints = make_int_list(boston) opponent_ints = make_int_list(opponent) print(boston_ints) print(opponent_ints) # print out the info for each game # and celebrate if boston won for i in range(len(boston_ints)): print(teams[i], boston_ints[i], opponent_ints[i]) # TODO: celebrate using the celebrate function # celebrate(points1, points2) celebrate(boston_ints[i], opponent_ints[i]) plot_goals(boston_ints, opponent_ints) main()