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 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
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
Write a program that takes, as input, five numbers and outputs the mean (average) and standard...
Write a program that takes, as input, five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x₁, x₂, x₃, x₄, and x₅, then the mean is: x = (x₁+ x₂+ x₃+ x₄+x₅)/5 and the standard deviation is: s = √(((x₁-x)²+(x₂-x)²+(x₃-x)²+(x₄-x)²+(x₅-x)²)/5) Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. Format your output with setprecision(2) to ensure...
What does Person-Centered Care or Patient and Family Centered Care mean to you as a consumer...
What does Person-Centered Care or Patient and Family Centered Care mean to you as a consumer and/or as a future provider of health care?
list 8 dimensions of person and family centered care
list 8 dimensions of person and family centered care
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT