Question: PYTHON programming assignment Assignment Overview This lab exercise provides practice with lists, functions and namespaces in Python. You will work with a partner on this
PYTHON programming assignment
Assignment Overview This lab exercise provides practice with lists, functions and namespaces in Python. You will work with a partner on this exercise during your lab session. Two people should work at one computer. Occasionally switch the person who is typing. Talk to each other about what you are doing and why so that both of you understand each step.
Benfords Law Benford's Law (sometimes called the First-Digit Law) is an observation about the distribution of first digits in many data sets: the number 1 occurs as the leading digit about 30% of the time, while larger numbers occur in that position less frequently (for example, 9 occurs as the first digit less than 5% of the time). As noted on Wikipedia: This result has been found to apply to a wide variety of data sets, including electricity bills, street addresses, stock prices, population numbers, death rates, lengths of rivers, physical and mathematical constants, and processes described by power laws (which are very common in nature).
Develop a program which will allow you to experiment with Benfords Law. The program will prompt the user for the name of an input file, read the contents of the file and count the leading digits, and then display the results. For simplicity, the program will assume that the data file contains integer numbers, with one value per line.
The programs output will be formatted for readability (see below).
Notes and Suggestions
1. The directory for this lab exercise contains three data files which you can use as you develop your program: city_part.txt the first 10 lines of the following file (a small file for resting) city_all.txt the population of every city and town in Michigan (1500+ lines) warblers.txt decades of counts of warbler observations (540,000+ lines)
2. There are three phases to this program. What are they? Which should you do first?
3. Requirement: you need a counter for each digit so use a list of counters and use the digit read from the file as an index into your list of counters. BEWARE: be careful that you do not count values with a zero as the leading digitthat can throw off your percentage calculation!
4. Requirement: your program must have a function open_file that continuously prompts for a file name until it opens and returns the file pointer.
5. The string method strip is useful for discarding leading and trailing whitespace.
6. The string method isdigit is useful to ensure that your program only processes integer numbers.
7. The string method format might be useful to align the output in columns.
8. Your program does not need to somehow compute the Benford values (e.g. 30.1%, 17.6%, ). Instead, you may use the values from the chart (or sample output).
This is the link to the assignment.. It includes full directions and also pictures of the programs output.
http://www.cse.msu.edu/~cse231/Labs/Lab09/lab09.pdf
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
