Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# takes the dictionary and prints its contents to the screen and to the file # sorted by the key def freqTable(countDict): print(ITEM, t, FREQUENCY)

image text in transcribed

image text in transcribed

# takes the dictionary and prints its contents to the screen and to the file # sorted by the key def freqTable(countDict): print("ITEM", "\t", "FREQUENCY")

## 5. __________________ ## print the dictionary parameter sorted by the key to the screen # takes a list of numbers and an empty dictionary # builds the dictionary with earthquake frequencies # where the key is the magnitude and the value is the frequency with which such an earthquake occurred # returns a list of modes def myMode(aList, countDict):

## 3. _____________________________ ## iterate over a list and build a dictionary called countDict ## to store the frequency of each value in aList parameter maxCount = ## 4. _______________find the highest value in a value componet of the dictionary modeList = [ ] ## creates a list of modes since there may be more than one mode for item in countDict: if countDict[item] == maxCount: modeList.append(item) return modeList

# takes a list of numbers and returns a median value - write your own code, do NOT use a built-in method median def myMedian(aList):

## 2. _________________________ ## deep copy of a list and then sort the copy ## find the median value - middle value if the length odd ## average of 2 middle values otherwise return med

# opens a file and extracts all earthquake magnitudes # into a list of floats and returns that list def makeMagList(): quakefile = open("earthquakes.txt","r") headers = quakefile.readline() maglist = [ ] for aline in quakefile: vlist = aline.split() print(vlist) maglist.append(float(vlist[1])) return maglist def myMain(): magList = makeMagList() print(magList) ## 1. ______________________________ ## print mean (use built in functions sum and len) frequencyDict = {} med = myMedian(magList) print("median: ", med) mod = myMode(magList, frequencyDict) print("mode: ", mod) freqTable(frequencyDict)

myMain()

2. Download the program earthquakestats.py. It is supposed to calculate statistics for the list of earthquakes provided in a text file. The statistics to calculate include the mean, the median, the mode, and the frequency table of all earthquake magnitudes. The shell for the code is written and you are not to change the shell itself - you are to replace comments with code - the comments that need to be replaced have numbers that indicate the order of replacement. When the program is done, if ran on provided earthquakes.txt, it should produce the following statistics to the screen: mean: 3.55 median: 3.2 mode: [2.9,3.2] \begin{tabular}{ll} 3.1 & 7 \\ 3.2 & 20 \\ 3.3 & 2 \\ 3.4 & 4 \\ 3.5 & 7 \\ 3.6 & 1 \\ 3.7 & 1 \\ 3.8 & 3 \\ 4.0 & 1 \\ 4.2 & 1 \\ 4.3 & 2 \\ 4.4 & 1 \\ 4.5 & 2 \\ 4.6 & 8 \\ 4.7 & 3 \\ 4.8 & 10 \\ 4.9 & 7 \\ 5.0 & 4 \\ 5.1 & 4 \\ 5.2 & 5 \\ 5.4 & 1 \\ 5.5 & 1 \\ 5.6 & 1 \\ 5.8 & 1 \\ 5.9 & 2 \\ 6.1 & 2 \\ \hline \end{tabular}

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_2

Step: 3

blur-text-image_3

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

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago