Per the program requirements in the \"comment section,\" I wanted to know to hav
ID: 3916541 • Letter: P
Question
Per the program requirements in the "comment section," I wanted to know to have someone review my code and see if there are any suggestions or comments. For instance, what if the high score, i.e. 10.0, is listed more than once. Do I need to somehow add this to my code?
## At certain Olympic events, there are 5 judges.
## To determine an athlete's final score for the event,
## the highest and lowest judges' scores are discarded
## and then the average of the rest of the scores is calculated. Assume that the
## array 'scores' contains the judges' scores.
## Write a function that accepts as an arguement a list
## of scores and returns the athlete's final score.
##
## (Hint: Add up all the scores in the array. Find the highest and lowest scores
## and subtract them out. Divide the sum by len(scores) - 2 and return the average.)
## ListScores = [5, 5, 5, 5, 5]
## ListScores = [0, 1, 2, 3, 4]
name = input("Enter athlete's last name: ")
ListScores = []
size = len(ListScores)
total = 0.0
def main():
total = 0
for score in range(1,6):
while True:
score = float(input("Enter athlete's score between 0 and 10: "))
if (score >= 0) and (score <= 10):
break
else:
print("Invalid Score")
ListScores.append(score)
for score in range(len(ListScores)):
total += ListScores[score]
print("Total Score:", ListScores,"=",total)
print("Minimum Score:",min(ListScores), "Maximum Score:",max(ListScores))
def finalScore(finalScore):
total = 0
minScore = ListScores[0]
maxScore = ListScores[0]
for score in ListScores:
if (score < minScore):
minScore = score
for score in ListScores:
if (score > maxScore):
MaxScore = score
score = sum(ListScores) - (minScore + maxScore)
return (score/3)
main()
fs = finalScore(finalScore)
print(name," Final Score: ",format(fs, '.2f'))
Explanation / Answer
I don't think that if there is a repetition of the highest show, it needs to be mentioned. There must be only one high and one low score in order to determine the athlete final score out of the remaining. If there are more than 1 same highest score, it may also happen that all the judges give a score of 10. In this case, the average comes out to be 0 as there won't be any highest or lowest score. So, only one highest and lowest score must be considered regardless of the score being repeated.
Another way you can solve this problem is by sorting the score array and then finding the average of the 2,3,4 scores, ignoring the first and the last score of the athlete. This way would not even consider the repetition part of the score as the score array will be in a sorted way.
I hope this helps you with your problem.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.