''' DS2000 Fall 2024 Sample code from class - practice reading from a file 9/17/24 What we're doing today: * Prompt the user for filename * Open the file: with open(filename, "r") as infile: * Read each line, one at a time, save in a variable * Calculate: range, min, max, median, mean, std dev, threshold * Communication: plotting, print ''' import matplotlib.pyplot as plt NUM_LINES = 3 def main(): # Step one: gather data, filename from the user and then # data from the file itself filename = input("Name of file?\n") with open(filename, "r") as infile: sal_one = float(infile.readline()) sal_two = float(infile.readline()) sal_three = float(infile.readline()) # computations... average, min min_salary = min(sal_one, sal_two, sal_three) total_sal = sal_one + sal_two + sal_three avg_sal = total_sal / NUM_LINES # Communication: report comps to the user print("First salary:", sal_one) print("Minimum salary:", min_salary) print("Average salary:", avg_sal) # Communication: plot the salaries # x value - row in file # y value - salary plt.plot(1, sal_one, "s", color = "magenta") plt.plot(2, sal_two, "s", color = "magenta") plt.plot(3, sal_three, "s", color = "magenta") plt.title("Boston City Salaries 2023") plt.xlabel("Salary Number") plt.ylabel("Annual Salary ($)") plt.show() main()