''' DS2000 Spring 2022 Sample code from class - using lists to remember ALL the jeopardy data! What questions can we ask about this data, if we save all the amounts in a list? - min/max values Amy won? - range of values - Std deviation (how far from the mean) - median - categorize data - looking for patterns ''' import matplotlib.pyplot as plt JEP_FILE = "schneider.txt" def main(): amounts = [] # Step one: gather data by reaeding from the file with open(JEP_FILE, "r") as infile: while True: amount = infile.readline() final = infile.readline() if amount == "" or final == "": break # If we get here, amount and final have real data amount = float(amount) amounts.append(amount) # Step two: computations # Compare first three games to last three games first_three = amounts[0] + amounts[1] + amounts[2] last_three = amounts[38] + amounts[39] + amounts[40] # Get the min and max of the amounts won max_won = max(amounts) min_won = min(amounts) low = 25000 medium = 45000 low_count = 0 medium_count = 0 high_count = 0 for amount in amounts: if amount <= low: low_count += 1 elif amount <= medium: medium_count += 1 else: high_count += 1 game_cats = [low_count, medium_count, high_count] # Step three: communicate! # sanity-check by printing out the list print(amounts) print("Amount won in first three games:", round(first_three)) print("Amount won in last three games:", round(last_three)) print("Max/min amounts won:", max_won, "/", min_won) print("Low games:", low_count, "\n" "Medium games:", medium_count, "\n" "High games:", high_count) # Create a plot for the categories of games (high/low/med) plt.bar([0, 1, 2], game_cats, color = ["aqua", "limegreen", "fuchsia"]) plt.legend() plt.title("Schneider Jeopardy! results by category") plt.ylabel("Number of games") plt.xticks([0, 1, 2], ["Low-scoring", "Med-scoring", "High-scoring"]) main()