Computers and Technology

A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set of numbers. Define these functions, median and mode, in a module named stats. py. Also include a function named mean, which computes the average of a set of numbers. Each function should expect a list of numbers as an argument and return a single number. Each function should return 0 if the list is empty. Include a main function that tests the three statistical functions using the following list defined in main: List: [3, 1, 7, 1, 4, 10]
Mode: 1
Median: 3.5
Mean: 4.33333333333
#Here is the code I am using:
def median(list):
if len(list) == 0:
return 0
list. sort()
midIndex = len(list) / 2
if len(list) % 2 == 1:
return list[midIndex]
else:
return (list[midIndex] + list[midIndex - 1]) / 2
def mean(list):
if len(list) == 0:
return 0
list. sort()
total = 0
for number in list:
total += number
return total / len(list)
def mode(list):
numberDictionary = {}
for digit in list:
number = numberDictionary. get(digit, None)
if number == None:
numberDictionary[digit] = 1
else:
numberDictionary[digit] = number + 1
maxValue = max(numberDictionary. values())
modeList = []
for key in numberDictionary:
if numberDictionary[key] == maxValue:
modeList. append(key)
return modeList
def main():
print ("Mean of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: "), mean(range(1, 11))
print ("Mode of [1, 1, 1, 1, 4, 4]:"), mode([1, 1, 1, 1, 4, 4])
print ("Median of [1, 2, 3, 4]:"), median([1, 2, 3, 4])
main()
The Error that I am getting is on Line 14: AttributeError: 'range'object has no attribute 'sort'.
Also on Line 36:
Line36: 10]: "), mean(range1, 11)).

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 20:00, serellehunt
Which type of file can be used to import data into a spreadsheet?
Answers: 1
image
Computers and Technology, 23.06.2019 09:30, kreshnikolloma
You wanted to look up information about alzheimer's, but you were unsure if it was spelled "alsheimer's" or "alzheimer's." which advanced search strategy would be useful? a) a boolean search b) using a wild card in your search c) trying different search engines d) doing a search for "alsheimer's not alzheimer's" asap. ill give brainlist.
Answers: 1
image
Computers and Technology, 25.06.2019 13:30, jaycie16
Which tab contains the font style attributes? home insert review view
Answers: 1
image
Computers and Technology, 25.06.2019 16:30, tasha7121
The diagram gives descriptions of three jobs in the energy career cluster. the middle circle is a characteristic that is common to all three careers.
Answers: 1
Do you know the correct answer?
A group of statisticians at a local college has asked you to create a set of functions that compute...

Questions in other subjects: