Charitable assassins

Challenge
No

The Northville Rotliokiw Murder Club raises money for charity by taking murder bounties. Bounties have two rewards: dead and deader. The first one is the money charged for a regular murder, without any frills. The second is for a splashy murder that will make the papers. The difference between the two is called the splash. So if the dead (normal) reward is H5,000 and the deader reward is H7,000, the splash is H2,000.

BTW, they don't use $. They use a currency unit called the Helpie, abbreviated H. All currency values are converted into H.

Download this data set. Here's part of it:

  • Target,Region,Dead,Deader
  • Aisha,central,84789,131902
  • Andreas,central,60528,103209
  • August,south,89564,103189
  • Bertha,east,91941,137909

Each record has four fields. Here they are, with their validation rules.

  • Target name. Cannot be empty.
  • Region. One of central, east, or south. Extra leading or trailing spaces are OK, and case doesn't matter, So " East " is valid, but "s0uth" is not.
  • Dead reward. Integer, zero or more.
  • Deader reward. Integer, zero or more.

Only include valid records in your analysis.

Write a program to show the average splash for each region. Use at least three functions. Using the data machine functions from this textbook might be easiest. Like cleaning the record set, adding splash to the data set as a computed field, getting a record subset for each region, and so on. Use the statistics module if you want; I did in my solution.

Here's what your program's output should be:

  • Bounties
  • ========
  •  
  • Splash by region
  •  
  • Counts
  • ------
  • Valid records: 45
  • Invalid records: 5
  • Total records: 50
  •  
  • Region mean splash
  • ------ ---- ------
  • Central: 36453.7
  • East: 15022.7
  • South: 14326.8
  •  
  • Region with the highest splash: Central

No, don't write a program with just a bunch of print statements. Someone tries that every so often. Your program's output should change if the data changes.

Include the record counts as shown.

Write a program to read all the data in the CSV file, perform the calculations, and output the results in the format shown. The averages should be rounded to one decimal place, as you can see. The usual coding standards apply.

Upload your solution here, as usual, not to Moodle.

Attachments