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 <= 3: 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)
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 <= 3:
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.
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4e9f5a4e-733b-4ef8-89d9-ff335bcd5624%2F4726ca32-9bd7-48f0-92ac-27dfbf0bb088%2F9iu5fo4_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)