Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language: Python Program used: PyCharm Interpreter: 3.6.1 at ~/anaconda/bin/python ----- ----- Starter code: https://pastebin.com/NgrECZQ7 candidates_2016: https://www.dropbox.com/s/oc8ws0qfz01664n/sk_election_candidates_2016.csv?dl=1 votecounts_2016: https://www.dropbox.com/s/ucgaf263q2x3qrm/sk_election_votecounts_2016.csv?dl=1 ----- YOU JUST NEED QUESTION #8 FROM

Language: Python

Program used: PyCharm

Interpreter: 3.6.1 at ~/anaconda/bin/python

-----

image text in transcribed

-----

Starter code: https://pastebin.com/NgrECZQ7

candidates_2016: https://www.dropbox.com/s/oc8ws0qfz01664n/sk_election_candidates_2016.csv?dl=1

votecounts_2016: https://www.dropbox.com/s/ucgaf263q2x3qrm/sk_election_votecounts_2016.csv?dl=1

-----

YOU JUST NEED QUESTION #8 FROM THE STARTER CODE PROVIDED ABOVE.

Question 8 (4 points) Purpose: To practice writing data to a file Degree of Difficulty: Moderate to Tricky. File I/O can be frustrating Task: Write a function called write election_results that takes two arguments - a string representing the name of a file to be written, and the district database (a dictionary with all the electoral district information in it). Your function should open the named file for writing. and then write the district results, one per line as in the following example Arm River, 6187,SK,Greg Brkich Athabasca,1756, NDP, Buckley Belanger Batoche,4471,SK,Delbert Kirsch Details: You are creating a tabular file with the following columns: district name, winning party vote count, winning party name and winning candidate. You might wish to review Chapter 12 (pp.98-99) from the text book for an example of creating a tabular file. When the data has been written, be sure to close the file! Be very careful not to write to a file that contains important information: writing to a file that already exists will destroy the data that was there Hint: To build this function, it is probably a good idea to ignore writing to a file until you know the data has the correct format. To do this, simply use print instead of the write method. When the data has the right format, then figure out opening the file, writing to it, and then closing it. Testing: Before going on, you want to be sure that your function works properly. The starter file has the testing code, but it will be initially part of a comment. Uncomment the testing for this question while you are working on it and comment it out when you are finished

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions