Question: This is for an Intro to Python class: Modify your Assignment class to have an attribute called correct_answers that contains a list of strings corresponding
This is for an Intro to Python class:
Modify your Assignment class to have an attribute called correct_answers that contains a list of strings corresponding to the correct answers for that assignment. On a reading assignment, this would correspond to the correct quiz answers. On a programming assignment, this would correspond to the expected outputs for the assignment tests. This list should be provided in every assignment instance's constructor call.
You should also add a method called grade, which accepts a list of student responses, compares those to the expected responses, and returns a float equal to the fraction of correct responses multiplied by the total number of possible points. This should work on all types of assignments.
The expected output argument should be the last argument in any constructor call.
Assignment Class:
class Assignment:
def __init__(self, num_points): self.num_points = num_points
class ReadingAssignment(Assignment): def __init__(self,num_points, reading_url, quiz_url): Assignment.__init__(self, num_points) self.reading_url = reading_url self.quiz_url = quiz_url class ProgrammingAssignment(Assignment): def __init__(self, num_points, description): Assignment.__init__(self, num_points) self.description = description
Example Input:
a1 = ReadingAssignment(4, 'some_reading_url', 'url_for_quiz', ['answer 1', 'answer 2', 'answer 3', 'answer 4'])
a2 = ProgrammingAssignment(10, 'description...', ['output 1', 'output 2']) print(a1.correct_answers) print(a2.correct_answers) print(a1.grade(['answer 1', 'incorrect', 'answer 3', 'answer 4'])) print(a2.grade(['output 1', 'incorrect']))
Example Output:
['answer 1', 'answer 2', 'answer 3', 'answer 4'] ['output 1', 'output 2'] 3.0 5.0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
