Microsoft Word - Project_08.docx CSE 231 Fall 2018 Programming Project 8 This assignment is worth 50 points (5.0% of the course grade) and must be completed and turned in before 11:59 on Monday,...

The files attached below are the project assignment. The PDF explains the project and the excel spreadsheets are the files you need to open.


Microsoft Word - Project_08.docx CSE 231 Fall 2018 Programming Project 8 This assignment is worth 50 points (5.0% of the course grade) and must be completed and turned in before 11:59 on Monday, November 12, 2018. Assignment Overview • Dictionaries • Lists and Tuples Assignment Background Diabetes is a disease that affects the production of insulin, which helps regulate the glucose levels in the blood. Many health related complications like heart disease and obesity have been linked to diabetes. The International Diabetes Federation (IDF) is comprised of over 220 countries and over 230 national diabetes associations in an effort to raise awareness on the problems this disease causes around the world. The IDF has published a diabetes atlas since 2000 that provides data about the prevalence of the disease in seven regions: North America and Caribbean, South and Central America, Middle East and Northern Africa, Africa, Europe, South East Asia, and the Western Pacific (http://diabetesatlas.org/resources/2017-atlas.html). For this project, you will create a program that will store the information of diabetes prevalence, both type-1 and type-2, in over 220 countries within a dictionary. From this dictionary, you need to select a region to visualize the number of people with diabetes, their age group distribution, and gender distribution for all the countries covered by the selected region. You will use tables, bar charts and pie charts for data visualization. Project Specifications 1. You must implement the following functions: a) open_file() prompts the user to enter a filename containing the diabetes prevalence data. The program will try to open a file. An error message should be shown if the file cannot be opened. This function will loop until it receives proper input and successfully opens the file. It returns a file pointer. On most computers you will need to include the following argument in your open statement so the Unicode characters in these files can be read: encoding ="windows-1252" e.g. fp = open("diabetes_data_small.csv",encoding ="windows-1252") (Likely the original csv file came from an Excel spreadsheet on a MS Windows computer.) b) create_dictionary(file) This function receives the opened file object, reads the file, and creates the dictionary containing the diabetes prevalence information. The dictionary will have three keys (region, country, and age group). That is, it is a dictionary of CSE 231 Fall 2018 dictionaries of dictionaries of lists of tuples. The function returns the dictionary. For each line in the file, you need to read the following: country = line_list[1] region = line_list[2] age_group = line_list[3] gender = line_list[4] geographic_area = line_list[5] diabetes = int(float(line_list[6])*1000) population = int(float(line_list[7])*1000) tup = (gender, geographic_area, diabetes, population) # there is more needed here to properly set up the dictionary D D[region][country][age_group].append(tup) c) get_country_total(data) This function receives a dictionary from a specific region, and returns a new dictionary of tuples with the number of people with diabetes and the total population for each country—the country name is the key, the tuple has total number of people with diabetes followed by the total population for the country. d) display_table(data, region) This function receives a dictionary with the diabetes data for a specific region (the data returned from the get_country_total function), and the full name of the region. This function returns nothing. It displays (In alphabetical order!) the country name, number of people with diabetes, and the total population of that country. There are two header lines and at the bottom is one line with totals for diabetes and population. Truncate country names to 24 characters. The formatting string for entries in the table is: "{:<25s}{:>20,d}{:>16,d}" e) prepare_plot(data) This function receives a dictionary for a specific region. We want to plot the region by age group and gender, that is, combine all the countries in the region’s data so it can be displayed by age group and gender. It returns a new dictionary with the age group and gender as its keys—the value totals all the countries in the region’s data for that age group and gender. This data will be used to plot the bar chart and pie chart that visualizes the age group distribution per gender, and the gender distribution of people with diabetes respectively for all the countries in a specific region. f) plot_data(plot_type,data,title) This function receives a string indicating which plot will be used ("BAR" or "PIE"), a dictionary with the diabetes data for a specific region (the dictionary returned by the prepare_plot function), and the title of the plot. This function returns nothing. This function is already provided for this project. g) main() The main function of the program. This function begins by prompting for and opening a file. Next, this function will call the create_dictionary() function to CSE 231 Fall 2018 build the data dictionary. Then it will prompt the user for a region to visualize the data. If the region is a valid region, the program will display a table of the diabetes prevalence for each country represented by the region (the program will continue prompting until a valid region is entered). Then, the program will prompt the user whether they want to display the age group and gender distributions of the data and plot the data. For this prompt, the program only accepts yes/no answers! The program will stop once the user enters “quit” for the region prompt. Keep in mind that the program evaluates “Quit” and “qUIt” and “quiT” as the same word (Hint: Use the upper() function) 2. Hints and Suggestions a) Dictionaries can contain other elements like float, list, and even other dictionaries. How to access a dictionary with multiple keys? Just like any other dictionary: Dictionary = {‘KeyA’ :{ ‘Key1’: value_list1, ‘Key2’: value_list2}} Dictionary[KeyA][Key2] would give value_list2 b) Dictionaries, just like lists, are not always sorted. One way to sort a dictionary is by having a sorted list of keys. To get the list of keys on a dictionary, use the keys() function. c) Entering a non-existing or incorrect region can be a very troublesome error! Python has a way to try these conditions and avoid such errors. Deliverables The deliverable for this assignment is the following file: proj08.py – the source code for your Python program Be sure to use the specified file name and to submit it for grading via the Mimir system before the project deadline. Sample Output: Function Test create_dictionary Reads diabetes_data_tiny.csv Returns {'MENA': {'Afghanistan': {'20-24': [('Female', 'Urban', 6786, 442695), ('Male', 'Urban', 2699, 474429)], '35-39': [('Female', 'Urban', 17834, 237228), ('Male', 'Urban', 14852, 262910)], '50-54': [('Female', 'Urban', 21715, 117219), ('Male', 'Urban', 23055, 126786)], '65-69': [('Female', 'Urban', 14604, 57459), ('Male', CSE 231 Fall 2018 'Urban', 11716, 51738)]}, 'Egypt': {'20-24': [('Female', 'Urban', 60631, 1649047), ('Male', 'Rural', 53521, 2241365)], '35-39': [('Female', 'Rural', 180200, 1841436), ('Male', 'Rural', 153985, 1907127)], '50-54': [('Female', 'Rural', 256800, 1127517), ('Male', 'Rural', 185168, 1130588)], '65-69': [('Female', 'Urban', 251500, 477673), ('Male', 'Urban', 159297, 429078)]}}, 'WP': {'Australia': {'20-24': [('Female', 'Rural', 192, 82406), ('Male', 'Urban', 1550, 764040)], '35-39': [('Female', 'Urban', 11780, 733000), ('Male', 'Rural', 1424, 84157)], '50-54': [('Female', 'Rural', 5219, 81662), ('Male', 'Rural', 6533, 81384)], '65-69': [('Female', 'Urban', 83815, 554127), ('Male', 'Urban', 92794, 542297)]}, 'French Polynesia': {'20- 24': [('Female', 'Rural', 643, 5226), ('Male', 'Urban', 504, 7007)], '35-39': [('Female', 'Rural', 1016, 4416), ('Male', 'Rural', 807, 4500)], '50-54': [('Female', 'Urban', 1610, 5044), ('Male', 'Rural', 1287, 4363)], '65-69': [('Female', 'Urban', 825, 2391), ('Male', 'Urban', 792, 2374)]}}} Function Test get_country_total input data: {'Afghanistan': {'20-24': [('Female', 'Urban', 6786, 442695), ('Male', 'Urban', 2699, 474429)], '35-39': [('Female', 'Urban', 17834, 237228), ('Male', 'Urban', 14852, 262910)], '50-54': [('Female', 'Urban', 21715, 117219), ('Male', 'Urban', 23055, 126786)], '65-69': [('Female', 'Urban', 14604, 57459), ('Male', 'Urban', 11716, 51738)]}, 'Egypt': {'20-24': [('Female', 'Urban', 60631, 1649047), ('Male', 'Rural', 53521, 2241365)], '35-39': [('Female', 'Rural', 180200, 1841436), ('Male', 'Rural', 153985, 1907127)], '50-54': [('Female', 'Rural', 256800, 1127517), ('Male', 'Rural', 185168, 1130588)], '65-69': [('Female', 'Urban', 251500, 477673), ('Male', 'Urban', 159297, 429078)]}} Returns: {'Afghanistan': (113261, 1770464), 'Egypt': (1301102, 10803831)} Function Test prepare_plot Input: {'Australia': {'20-24': [('Female', 'Rural', 192, 82406), ('Male', 'Urban', 1550, 764040)], '35-39': [('Female', 'Urban', 11780, 733000), ('Male', 'Rural', 1424, 84157)], '50-54': [('Female', 'Rural', 5219, 81662), ('Male', 'Rural', 6533, 81384)], '65-69': [('Female', 'Urban', 83815, 554127), CSE 231 Fall 2018 ('Male', 'Urban', 92794, 542297)]}, 'French Polynesia': {'20-24': [('Female', 'Rural', 643, 5226), ('Male', 'Urban', 504, 7007)], '35-39': [('Female', 'Rural', 1016, 4416), ('Male', 'Rural', 807, 4500)], '50-54': [('Female', 'Urban', 1610, 5044), ('Male', 'Rural', 1287, 4363)], '65-69': [('Female', 'Urban', 825, 2391), ('Male', 'Urban', 792, 2374)]}} Returns:
Nov 12, 2020
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here