Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python: Introduction This assignment lets you practice with reading from a file, writing to a file, and using dictionaries. The data file name state_crime,csv is

Python:

Introduction

This assignment lets you practice with reading from a file, writing to a file, and using dictionaries.

The data file name state_crime,csv is shown below contains records of different types of reported crimes. The first line of the file contains a description of each column of data.

Here's a picture of file since it's too big to load.

Population State Totals.Property.All Totals.Property.Burglary Totals.Property.Larceny Totals.Property.Motor Totals.Violent.All Totals.Violent.Assault Totals.Violent.Murder Totals.Violent.Rape Totals.Violent.Robbery Year
313914040 United States 8975438 2103787 6150598 721053 1214464 760739 14827 84376 354522 2012
311587816 United States 9052743 2185140 6151095 716508 1206031 752423 14661 84175 354772 2011
309330219 United States 9112625 2168459 6204601 739565 1251248 781844 14722 85593 369089 2010
307006550 United States 9337060 2203313 6338095 795652 1325896 812514 15399 89241 408742 2009
304059724 United States 9774152 2228887 6586206 959059 1394461 843683 16465 90750 443563 2008
301621157 United States 9882212 2190198 6591542 1100472 1422970 866358 17128 92160 447324 2007
299398484 United States 10019601 2194993 6626363 1198245 1435123 874096 17309 94472 449246 2006
296507061 United States 10174754 2155448 6783447 1235859 1390745 862220 16740 94347 417438 2005
293656842 United States 10319386 2144446 6937089 1237851 1360088 847381 16148 95089 401470 2004
290788976 United States 10442862 2154834 7026802 1261226 1383676 859030 16528 93883 414235 2003

Directions

Write a python program to read the file, and produce a summary of the total reported crimes for each state. The report will look something like this, though don't worry if your list is not in alphabetical order:

State Reported Crimes Alabama 8,133,055 Alaska 1,198,047 ... Wyoming 834,588 United States 563,841,249 

There are a lot of fields in the data file, but you can simplify your life by using subtotal fields, Totals.Property.All and Totals.Violent.All.

Once you have the summary, change your program so it writes the summary to a file, crime_summary.txt.

Make sure you use a dictionary for this assignment. The obvious case is to use a key of state names and the value is the accumulated count of reported crimes. There might be a place for another dictionary as well, though you only need to use one.

Be sure to add a header comment to your program and any functions, and appropriate comments before other blocks of code.

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

Additional Factors Affecting Group Communication?

Answered: 1 week ago