Question: Program: Using Benfords Law to Detect Falsified Data (python) In an IDLE new window, create a program called benford.py. This program mainly consists of a

Program: Using Benfords Law to Detect Falsified Data (python)

In an IDLE new window, create a program called benford.py. This program mainly consists of a main() function and a call to main(). It must do the following:

Create a tally list that has nine elements, each of which is initially zero.

Prompt the user for the name of a data file and open it.

Use a for-loop to read each line in the file, splitting each line on the commas (line.split(,)) to create a list. The value after the final comma is the datapoint of which you want the leading digit. You should not make any assumptions about the number of spaces between the final comma and the datapoint at the end of the line, i.e., use strip() as shown above. (Note that you dont have to convert the datapoint to a string because its already a string. The entire 4 data file is made up of ASCII characters!) For the given digit, increment the tally list as appropriate. Dont forget to convert your digit to an integer.

Call the show digits() function after the tally has been completed. You may include this function in your code or else import it. If you import it, dont forget that it needs to be in your working directory or else in the path searched by Python.

Print tally.

Dont forget to include docstrings in your code!!! To test your code for a small data file, download pa6 test.dat from the homework Web page. You should get the following results:

import pa6

Enter file name: pa6_test.dat

Total number of datapoints = 13

Number of occurrences of leading digits: 5

digit measured predicted

1 1 4

2 1 2

3 1 2

4 1 1

5 1 1

6 1 1

7 2 1

8 2 1

9 3 1

[1, 1, 1, 1, 1, 1, 2, 2, 3]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!