This Python program analyzes survey responses about how well teacher salaries align with the cost of living. It reads data from a CSV file, validates responses, visualizes results using charts, and calculates the average rating using NumPy. The program provides clear insights into public opinion and funding preferences related to teacher pay.
The program begins by reading survey data from a CSV file and uses custom functions to validate the age, rating, and funding source for each response. It stores valid data in lists and counts, then uses Matplotlib to generate a histogram and pie chart to visualize the results. Finally, it calculates the average rating using NumPy and displays all results in a clear and organized way.
🔹 check_age(age_one)
Checks if the age input is a valid integer between 0 and 150 and returns True or False accordingly.
🔹 check_linear_scale(rating_one)
Validates that the rating is an integer between 1 and 5, representing how well teacher salaries align with cost of living.
🔹 check_multiple_choice(choice_one)
Verifies that the funding choice matches one of the three valid survey options.
🔹 read_csv(file_name)
Opens the survey CSV file, validates each row of data using the three checking functions, collects valid ratings, and counts responses for each funding source.
🔹 plt_linear_rating(ratings)
Creates and displays a histogram that shows how many people gave each rating on the 1–5 scale.
🔹 plt_counts(federal, reallocation, taxes)
Generates a pie chart visualizing how many people selected each of the three funding options for increasing teacher salaries.
🔹 compute(ratings)
Calculates the average (mean) rating from the list of valid ratings using NumPy.
🔹 main()
Controls the overall program by calling the other functions, storing results, printing outputs, and displaying the two charts.
The program outputs a list of valid ratings, the number of responses for each funding option, and the average rating based on the survey data. It also generates a histogram showing how participants rated salary alignment and a pie chart displaying their preferred sources of funding for potential salary increases.
Programming With Data Using NumPy