Question

Must be written in Python3 A particular talent competition has 7 judges, each of whole awards...

Must be written in Python3

A particular talent competition has 7 judges, each of whole awards a score between 0 and 10 to each performer. A performer's final score is determined by dropping the highest and lowest score received, then averaging the 5 remaining scores. Define a class named ScoreCalculator that contains member variables and member functions based on the following:

member variables: list of scores

member function:

1) Initialization function: When creating an instance, create a score list as an initial value and store the created value as a member variable.

2) findHighest(): Functions that find and remove the highest score from member variables

3)findLowest(): Functions that find and remove the lowest score from member variables

4)calAvg() should calculate and return the average of the 5 scores that remain after dropping the highest and lowest scores the performer received.

You only need to define a class using only member variable(score) and 4 functions .

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class ScoreCalculator:
    """
    score calculator class
    """

    def __init__(self, scores):
        """
        creating object with scores
        :param scores: list of score
        """
        self.scores = scores

    def findHighest(self):
        """
        function to return highest score
        :return: highest score
        """
        return max(self.scores)

    def findLowest(self):
        """
        function to return lowest score
        :return: lowest score
        """
        return min(self.scores)

    def calAvg(self):
        """
        function to calculate average of score
        it first remove the highest and lowest score
        by calling above methods
        it only removes the first occurance id same highest/lowest
        score repeated
        then it calculate the average
        :return:
        """
        self.scores.remove(self.findHighest())
        self.scores.remove(self.findLowest())
        return float(sum(self.scores)) / float(len(self.scores))


# Testing above code
if __name__ == '__main__':
    scores = [7, 1, 9, 6, 3, 5, 8]
    obj = ScoreCalculator(scores)
    print("Average score %.2f" % obj.calAvg())

#######################################################################

#OUTPUT

Average score 5.80

Add a comment
Know the answer?
Add Answer to:
Must be written in Python3 A particular talent competition has 7 judges, each of whole awards...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A particular talent composition has 5 judges, each of whom awards a score between 0 and...

    A particular talent composition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer's final score is determined by dropping the lowest and the highest score received, then averaging the 3 remaining scores. Write a program that uses this method to calculate a contestant's score. It should include the following functions: double getJudgeData() should ask the user for a judge's score and validate the score....

  • A particular talent competition has five judges, each of whom awards a score between 0 and...

    A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and the lowest score received then averaging the three remaining scores. Write a program that does the following: 1. Reads names and scores from an input file into a dynamically allocated array of structures. The first number in the input file represents the...

  • Please Write in C++ (10-30) @ 11:55pm 1.9 HW7 This homework assignment gives you the opportunity...

    Please Write in C++ (10-30) @ 11:55pm 1.9 HW7 This homework assignment gives you the opportunity to practice functions, functions that call other functions, reference variables, logical statements (what is meant by logical statement is a statement such as if, if/else if, switch), and input validation, HW7 (Graded out of 100) A talent competition has 5 judges, each of whom awards a score between 0 and 10 for each performer. Fractional scores, such as 8.3, are allowed. A performer's final...

  • ***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions...

    ***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions -Learn to use reference variables Coding Guidelines for All Labs/Assignments (You will be graded on this) -Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). -Keep identifiers to a reasonably short length. -Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables,...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT