''' DS2000 Spring 2022 Counting US winter olympic medals ''' import matplotlib.pyplot as plt OLYMPIC_FILE = "us_medal_count.txt" def main(): # Step one: gather data from the file # File has one list's worth of data per line # x, x, x, x, ... with open(OLYMPIC_FILE, "r") as infile: years = infile.readline() golds = infile.readline() silvers = infile.readline() # Step two: computation # Turn strings into lists years = years.split(",") golds = golds.split(",") silvers = silvers.split(",") # Modify both lists so they contain integers (not strings) for i in range(len(years)): years[i] = int(years[i]) golds[i] = int(golds[i]) silvers[i] = int(silvers[i]) # Step three: communicate! # Sanity-check: print out what I've got print(len(years), "years:", years) print(len(golds), "gold medals:", golds) # Print out the number of golds per year for i in range(len(years)): print("In year", years[i], "we got", golds[i], "golds " "and", silvers[i], "silvers!") # Plot the golds # Scatter plot: give it two lists, one of x values # and one of y values plt.scatter(golds, silvers, color = "darkgoldenrod") plt.xlabel("Golds") plt.ylabel("Silvers") plt.show() # Plotting golds but it's backwards plt.plot(golds) main()