Answer to Question #313647 in Python for ABCD

Question #313647

Would you know how a gymnastics competition is scored? Well, for each performance, each judge gives a score in the range 1 to 10. Then, the highest and the lowest scores are canceled, and the rest are averaged. The average is the score of the performance.


For example, suppose there were 7 judges, and the performance gets the following scores.


9.20


9.00


8.75


9.40


9.60


8.90


9.60


The average would be 9.22 (that's (9.2+9.0+9.4+9.6+8.9)/ 5).


Write a python program that read 7 scores as input and outputs the average. The program should us an array of floats. Note that you need to determine the highest and the lowest score and exclude them in the computation.


Below is a sample output of this exercise.


Enter 7 scores: 9.20


9.00


8.75


9.40


9.60


8.90


9.60


High Score: 9.60


Low Score: 8.75


Average Score : 9.22



1
Expert's answer
2022-03-18T12:13:55-0400
#define empty list
arr = [] 
#input data manually
arr = [float(item) for item in input("Enter 7 scores with spaces: ").split()]
n = len(arr)
#find ligh score
def largest(arr,n):
    return (max(arr))
high = largest(arr,n)
print ("High Score: ",high)

#find low score
def smalest(arr,n):
    return (min(arr))
low = smalest(arr,n)
print("Low Score:",low)

#exclude high and low scores from average calculation
arr.remove(high)
arr.remove(low)

#find average score
def average(arr,n):
    return(sum(arr) / len(arr))
av = average(arr,n)
print("Average Score:",av)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS