""" Felix Muzny DS 2000 Lecture 5 September 20, 2024 A program to visualize the top 10 salaries in MA 2023 (from a file, with a loop!) """ import matplotlib.pyplot as plt FILENAME = "ma_salarytop10.txt" def main(): print("lec 5 - ma salaries WITH loop") # step 1 - gather data with open(FILENAME, "r") as salary_file: # memory/accumulator variable rank = 1 for line in salary_file: print(line) salary = int(line) plt.bar(rank, salary, color= "red") rank = rank + 1 # the same as rank += 1 # if we want to make our program ultimately flexible! plt.title("top " + str(rank - 1) + " MA salaries 2023") plt.xlabel("rank") plt.ylabel("total salary") plt.show() main()