subject

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)).

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:00
Write a program which asks you to enter a name in the form of first middle initial last. so you might enter for example samuel p. clemens. use getline to read in the string because it contains spaces. also, apparently the shift key on your keyboard doesn’t work, because you enter it all lower case. pass the string to a function which uses .find to locate the letters which need to be upper case and use toupper to convert those characters to uppercase. the revised string should then be returned to main in the form last, first mi where it will be displayed.
Answers: 1
question
Computers and Technology, 22.06.2019 23:50
You need to design a circuit that implements the functions in the following table: s0 s1 function0 0 a + 10 1 a – b1 0 a + b1 1 a – 1s0 and s1 are 1-bit control inputs to select the function of the circuit. inputs a and b are 4-bitnumbers in 2s complement form. the output is also a 4-bit number in 2s complement form.you are allowed to use only one ttl 7483 4-bit adder to implement all the functions. but anynumber of other components (except the adder) can be used.hint: design a combinational logic circuit to modify the input b and the “carry input” of theadder depending on the control inputs s0 and s1.important: lab grade will depend on the working of the circuit & will be checked of by your labinstructor.1. is the output valid for the following input combinations: a. s0 = 0, s1 = 0, a = 7, b = 3? b. s0 = 0, s1 = 1, a = 7, b = 3? c. s0 = 1, s1 = 0, a = -4, b = -5? d. s0 = 1, s1 = 1, a = -8, b = 6? 2. what is the range of inputs (for both a and b) that will produce the valid output for all the functions?
Answers: 3
question
Computers and Technology, 23.06.2019 19:30
What are loans to a company or government for a set amount of time
Answers: 1
question
Computers and Technology, 24.06.2019 07:00
Selective is defined as paying attention to messages that are consistent with one’s attitudes and beliefs and ignoring messages that are inconsistent.
Answers: 1
You know the right answer?
A group of statisticians at a local college has asked you to create a set of functions that compute...
Questions
question
Mathematics, 16.11.2020 19:20
question
Social Studies, 16.11.2020 19:20
question
Arts, 16.11.2020 19:20
question
Mathematics, 16.11.2020 19:20
question
Business, 16.11.2020 19:20
Questions on the website: 13722367