F01.justanswer.com
I210: Information Infrastructure IMastery Project 2Always backup your work to a system that you don’t control, such as OneDrive or Google Drive, in case something goes wrong with Canvas. These put a timestamp on your work that can be used to prove when it was done. We cannot accept timestamps from your local machine.You are responsible for making sure your work is submitted by the due date on Canvas, so it is strongly advised that you verify the submission once you’ve turned it in. We accept Mastery Projects up to 24 hours late, for a 20% penalty.As a reminder, while working on this project, you may use anything on the Canvas section for I210, as well as Zybooks. You may use any notes (physical or online) taken for I210. Using code you found online from outside of this class or code that you did not write that is not Zybooks code or from our Canvas section will constitute academic misconduct. If you are unsure, ask first.If you have questions about what we want you to do in this Mastery Project, ask in Piazza. If you get stuck writing your code and need help, come to an Office Hour. Start early so that there’s as much time as possible to get help!Mastery Project 2 requires you to use pieces from Lesson 11 – Lesson 21, so you won’t be able to complete all elements until you’ve done this material. Keep an eye out for pieces that you’ll need! -142870228600In this project we use real-world data from the MIT Election Data and Science Lab. The dataset you will be using is a report of the general elections from 1976 until 2016. Make sure you open the data in a spreadsheet program and/or in your code editor so you can see what you’re working with before manipulating the data with code.There are 4 parts to Mastery Project 2:Read in and format the data from 1976-2016-president.csvWrite a function that takes the name of the file (the default should be 1976-2016-president.csv) and a general election year from the user. The function will read the CSV data in using a DictReader and return a nested list where each element is a tuple. After reading in the whole file, use a list comprehension to read the rows for the given year. When the data is loaded, let the user know the action is complete with a message. It’s a good idea when working with files to also include how large the dataset is that we are working with (in this case, how many rows).Create a module for sorting and displaying the data Write a module for importing the data that includes the following functions:A function (table_print), that prints the data in the table formatted with two columns of the given width and the given header(hint: see lesson 18)A function that uses insertion sort or selection sort, to sort a list. The input is a nested list (list of lists) and a column (col). The function sorts the rows of that list based on the values in the column col.(hint: see lesson 16)A function named tallied_data() that takes in a nested list (Use this on the data from part 1, but it should be able to be used to solve similar problems), indices for two columns and returns a tallied list. The inputs are:a nested list,an index for the ‘reference column’/ ‘category’ (col_ref)another index for the column to be tallied (col_tally)this function returns a list of tuples where each element is a tuple with two elements, the first one is the reference/category and the second one is the tallied sum for all the rows that have the reference. This list will be returned sorted in descending order based on the tallied numbers. (hint: see Lesson 19)For example using the tallied_data() function from part c: data = [[Indiana, 2, 'Clinton', 4], [‘Colorado’, 2, ‘Bush’, 56], [‘Colorado’, 2, 'Clinton', 100], [‘Illinois’, 3, ‘Gore’, 8], [Oregon, 3, 'Clinton', 4], [Indiana, 4, ‘Bush’, 2]]print(tallied_data(data, 2, 3)) will display [('Clinton', 108), ('Bush', 58), ('Gore', 8)]print(tallied_data(data, 0, 3)) will display[(‘Colorado’, 156), (‘Illinois’, 8), (‘Indiana’, 6), (‘Oregon’, 4)]Identify a focus to refine the dataAsk the user for the file name, and the general election year they are interested in. Make sure to use error handling if the user enters a wrong file name or a wrong year (either not a general election year, or not in the range 1976-2016, or not a valid number at all). We want to be able to write functions to answer 4 of the following 6 specific questions using the data:Given an election year, how many votes did each candidate receive total (in the whole country)? The result should be printed in a descending order in a table. Given an election year, how many votes did each party receive total (in the whole country)? The result should be printed in a descending order in a table. Given an election year, how many votes were “write-in” votes?Given an election year, who won the popular vote? Given an election year, what is the state where each candidate got the most votes?Given a candidate name, which year(s) did the candidate run, and how many votes did they get each year?Ask the user which question they want to answer and then print a table relevant to the question and print a statement if necessary to answer the question.BONUS: Save the results to a fileExtend your code to print more information and save the results to a file. Given an election year, what was the outcome of the popular vote in that year? Print out the results showing each candidate, their party, the total number of votes they received, and what percentage of the votes they received. Format the data so it is human readable within the file. The data should be in plain text and not formatted as CSV, however, we do expect labels and some amount of formatting -- someone reading the file should be able to understand what each set of results is showing. Ask the user if they want to continue to print to the console and output the file, or just output the file.In each section, functionality will account for about 50% of the grade. 10% of the points will be awarded for proper use of modules. Please do not write the entire project in main! Any piece of the problem that was to be in the module, as described above, should be in the module.10% of the points will be awarded for proper use of error handling. Make sure when you ask the user for the file name and general election year that you can handle errors 10% of the points will be awarded for proper use of functions. Please do not write the entire project in main! Any discrete piece of the problem should be in a function.10% of the points will be for observation of programming conventions, good naming, commenting, not duplicating code, etc. We expect you to produce well-written, well-organized code, not just code that works. The last 10% is for completing the turn-in sheet on the next page, which you should submit along with your Python program.I210 Turn-In Sheet: Mastery Project 2Fill in the sheet anywhere there is a yellow arrow! This is IN ADDITION to your Python file.→ Your name:?For this assignment, please submit:This “turn in” worksheet (completed - required)Your Mastery Project 2, named MP2-YourLastName-YourFirstName.py and mymod.pyPart 1 (3 pts)→ What Python module did you use to read in the data??→ What data type is the election data you loaded??→ How does the user know when the data is done loading? Part 2 (2 pts)→ How did you tally the votes for each query? → What data structure did you use to store the results??Part 3 (4 pts)→ What algorithm did you use to sort the data?→ Why did you choose that method? → How did you approach refining the data to only the requested election year?→ What approach did you take to formatting the output in a table?Overall (1 pts)→ Your main should be minimal -- most of the code should reside in discrete functions -- briefly explain how you decided what to put in each function for this program???Bonus (Optional)→ If you did this section, what mode did you write to the file in?→ If you did this section, how did you handle formatting the output written in the file? ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.