Question (see pic) Code: ( see question below the code) : Note: Dont forget "classes" classes = {} class Document: #TO DO: define the constructor method, __init__ and then initialize values #def...


Question(see pic)


Code: (see question below the code):



Note: Dont forget "classes"


classes = {}


class Document:
  #TO DO: define the constructor method, __init__ and then initialize values
  #def __init__(___, ___):
    # initilialize values here

  #TO DO: define the method add_words
  #def add_words(___, ___):


  #TO DO: define the method submit
  #def submit(___):

  #TO DO: define the method get_grade
  #def get_grade(___):

  #TO DO: add new attributes and methods here
    #
    #
    #

    key = 0

    def __str__(self):
        document_info = f"This Document instance has the following stats.\n"
        document_info += f"1. word count: {self.word_count}\n"
        document_info += f"2. status: {self.status}\n"
        document_info += f"3. grade: {self.grade}\n"
        document_info += f"4. number of times the grade was requested before the document was submitted: {self.asked_grade_before_submission_count}\n"

        #TO DO: Fill in the blanks
        if self.key <=>
            document_info += ""
        elif self.key == 4:
            document_info += f"This Document instance has _ instance attribute/s."
        elif self.key == 5:
            document_info += f"The class used to create this object has _ method/s."
        elif self.key == 6:
            document_info += f"The class used to create this object has _ class attribute/s."
        elif self.key == 7:
            document_info += f"The class used to create this object has _ special method/s."
        return document_info


def is_command_valid(command):
    global classes
    #TO DO: add validation steps here
    return True

if __name__ == "__main__":
    while(True):
        command = input()
        if command == 'exit':
            break
        elif command.find(" = ") != -1:
            exec(command)
            print("Valid command")
        else:
            if is_command_valid(command):
                exec(command)
                print("Valid command")
            else:
                print("Invalid command")
    print(essay)


Create a Python class, Document.<br>Using PYTHON: The instances of this class have the following attributes: word_count, status, grade, asked_grade_before_submission_count and the following methods: add_words, submit,<br>get_grade,<br>(1) key - a class attribute that determines the output when printing the document instance. It has a value of 0 by default.<br>Let us also add these additional method/s for the Document class:<br>str . For this exercise, we will add the following attribute/s:<br>(1) copy_content - takes in source_document as a parameter of type Document then updates the word_count of the destination document (or the document where this method was invoked). The<br>word_count is updated accordingly so that the content of the destination document is replaced by the source document.<br>(2) append_content - takes in source_document as a parameter of type Document then updates the word_count of the destination document. The word_count is updated such that the content of<br>the source document is appended to the destination document.<br>Input Format<br>The inputs are commands that can access an attribute or invoke a method of a Document instance. These commands can either be valid or invalid.<br>Constraints<br>String arguments when creating a Document instance and when invoking the add words method will be limited to 1000 characters at maximum. Only alphanumeric characters will be used as an<br>argument to these methods.<br>The invalid commands only include those that are trying to access an attribute of the object that is undefined.<br>Format<br>The output will be composed of 5 - 6 lines. The first five lines show the stats of the document being printed. The other is either an empty string or a string that shows one out of many descriptions<br>of the Document instance being printed.<br>Sample Input 2<br>essay = Document (

Extracted text: Create a Python class, Document. Using PYTHON: The instances of this class have the following attributes: word_count, status, grade, asked_grade_before_submission_count and the following methods: add_words, submit, get_grade, (1) key - a class attribute that determines the output when printing the document instance. It has a value of 0 by default. Let us also add these additional method/s for the Document class: str . For this exercise, we will add the following attribute/s: (1) copy_content - takes in source_document as a parameter of type Document then updates the word_count of the destination document (or the document where this method was invoked). The word_count is updated accordingly so that the content of the destination document is replaced by the source document. (2) append_content - takes in source_document as a parameter of type Document then updates the word_count of the destination document. The word_count is updated such that the content of the source document is appended to the destination document. Input Format The inputs are commands that can access an attribute or invoke a method of a Document instance. These commands can either be valid or invalid. Constraints String arguments when creating a Document instance and when invoking the add words method will be limited to 1000 characters at maximum. Only alphanumeric characters will be used as an argument to these methods. The invalid commands only include those that are trying to access an attribute of the object that is undefined. Format The output will be composed of 5 - 6 lines. The first five lines show the stats of the document being printed. The other is either an empty string or a string that shows one out of many descriptions of the Document instance being printed. Sample Input 2 essay = Document ("Roses are red") classes ['essay'] = essay essay_draft = Document ("Violets are blue") classes ['essay_draft'] = essay_draft essay. append_content(essay_draft) essay.add_words ("Sugar is sweet and so are you") essay.key_1 essay.delete( ) essay.key = 0 exit Sample Input 0 essay = Document ("Roses are red") classes ['essay'] = essay essay_draft = Document("Violets are blue") classes ['essay_draft'] = essay_draft essay.append_content(essay_draft) essay.key = 0 exit Sample Output 0 Valid command Valid command Valid command Valid command Valid command Sample Output 2 Valid command Valid command Valid command Valid command This Document instance has the following stats. 1. word count: 6 Valid command Valid command Valid command 2. status: draft 3. grade: awaiting submission 4. number of times the grade was requested before the document was submitted: 0 Invalid command Invalid command Valid command This Document instance has the following stats. 1. word count: 13 2. status: draft 3. grade: awaiting submission 4. number of times the grade was requested before the document was submitted: 0 Sample Input 1 essay = Document ("Roses are red") classes['essay'] = essay essay_draft = Document("Violets are blue") classes ['essay_draft'] = essay_draft essay.append_content (essay_draft) another_essay_v2 = Document ("Go away Anna! Okay bye.") essay.copy_content(another_essay_v2) essay.key = 0 Sample Input 3 essay = Document ("Roses are red") classes ['essay'] = essay essay_draft = Document ("Violets are blue") classes ['essay_draft'] = essay_draft essay.append_content(essay_draft).append_content(essay_draft) essay.add_words("Sugar is sweet and so are you") essay.key_1 essay.delete() essay.key = 0 exit exit Sample Output 1 Valid command Valid command Valid command Valid command Valid command Valid command Valid command Valid command This Document instance has the following stats. 1. word count: 5 Sample Output 3 Valid command Valid command Valid command Valid command Valid command 2. status: draft 3. grade: awaiting submission 4. number of times the grade was requested before the document was submitted: 0 Valid command Invalid command Invalid command Valid command This Document instance has the following stats. 1. word count: 16 2. status: draft 3. grade: awaiting submission 4. number of times the grade was requested before the document was submitted: 0
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here