Question

In: Computer Science

The centered average of a list of numbers is the arithmetic mean of all the numbers...

The centered average of a list of numbers is the arithmetic mean of all the numbers in the list, except for the smallest and largest values. If the list has multiple copies of the smallest or largest values, only one copy is ignored when calculating the mean. For example, given the list [1, 1, 5, 3 5, 10, 8, 7], one 1 and 10 are ignored, and the centered average is the mean of the remaining values; that is, 5.2. Use the function design recipe to develop a function named centered_average. The function takes a list of integers. (Assume that the list has at least three integers). The function returns the centered average of the list. Hint: In this exercise you are permitted and encouraged to use Python's min and max functions.

**** YOU CANNOT USE THE FOLLOWING:

list slicing (e.g., lst[i : j] or (lst[i : j] = t)  the del statement (e.g., del lst[0])  Python's built-in reversed and sorted functions.  any of the Python methods that provide list operations; e.g., append, clear , copy , count, extend, index, insert, pop, remove, reverse and sort  list comprehensions

Solutions

Expert Solution

Code and output

Code for copying

def centered_average(list1):
s=0
count=0
  
for i in list1:
s+=i
count+=1
s-=min(list1)
s-=max(list1)
  
  
count=count-2
return s/count
list1=list(map(int,input("Enter the list : ").rstrip().split()))
print("The centered average is {}".format(centered_average(list1)))

Code snippet

def centered_average(list1):
    s=0
    count=0
    
    for i in list1:
        s+=i 
        count+=1
    s-=min(list1)
    s-=max(list1)
    
    
    count=count-2 
    return s/count 
list1=list(map(int,input("Enter the list : ").rstrip().split()))  
print("The centered average is {}".format(centered_average(list1)))

Related Solutions

How are different types of arithmetic means like simple arithmetic mean, weighted arithmetic mean etc. calculated.?
How are different types of arithmetic means calculated.? like simple arithmetic mean, weighted arithmetic mean, arithmetic mean for continuous class ,  combined arithmetic mean.  
If 7,4 and 9 be the arithmetic mean of three seperate groups containing 6,2 and 5 observations respectively, then calculate the arithmetic mean of all the thirteen observations combined?
If 7,4 and 9 be the arithmetic mean of three seperate groups containing 6,2 and 5 observations respectively, then calculate the arithmetic mean of  all the thirteen observations combined? 
Write a function in Python to compute the sample mean of a list of numbers. The...
Write a function in Python to compute the sample mean of a list of numbers. The return value should be the sample mean and the input value should be the list of numbers. Do not use a built-in function for the mean. Show an example of your function in use.    Thank You
Write a function which receives a list and returns a number. In the list, all numbers...
Write a function which receives a list and returns a number. In the list, all numbers have been repeated twice except one number that is repeated once. The function should return the number that is repeated once and return it.write a python program for this question. use main function.
Make a list of all the possible sets of quantum numbers that an electron in an...
Make a list of all the possible sets of quantum numbers that an electron in an atom can have if n = 4. How many different states with n = 4 are there? Indicate on your list which states are degenerate (i.e. have the same energy as other n = 4 states). Assume that the electron is in a multi-electron atom (i.e. not the Hydrogen atom). Does the total number of states agree with the general rule that the number...
In Python, Given a list of numbers, return a list where all adjacent == elements have...
In Python, Given a list of numbers, return a list where all adjacent == elements have been reduced to a single element, so [1,2,2,3,3,2,2,4] returns [1,2,3,2,4]. You may create a new list or modify the passed in list (set function does not work in this case).
The _____________ is the square root of the arithmetic average of the squared deviations from the mean. In other words, it is simply the square root of the ______________.
The _____________ is the square root of the arithmetic average of the squared deviations from the mean. In other words, it is simply the square root of the ______________.data spread; population standard deviationStandard deviation; data spreadpopulation standard deviation; variancevariance; standard deviation
Count all nonzero elements, odd numbers and even numbers in a linked list. Code needed in...
Count all nonzero elements, odd numbers and even numbers in a linked list. Code needed in java.
Count all nonzero elements, odd numbers and even numbers in a linked list. Code needed in...
Count all nonzero elements, odd numbers and even numbers in a linked list. Code needed in java through single linked list.
Provided is a list of numbers. For each of the numbers in the list, determine whether...
Provided is a list of numbers. For each of the numbers in the list, determine whether they are even. If the number is even, add True to a new list called is_even. If the number is odd, then add False. num_lst = [3, 20, -1, 9, 10] **Please use Python**
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT