Create a Python class, Document.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Question (see pic) 

Code: (see question below the code)

Note: Dont forget "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(___):
  

  def __str__(self):
    #TO DO: Fill in the blanks
    document_info = f"This Document instance has _ instance attributes.\n"
    document_info += f"The class used to create this object has _ methods and _ class attribute.\n"
    document_info += f"This Document instance has the following stats.\n"
    #TO DO: Complete document_info by adding more lines below
      
    return document_info
  
if __name__ == "__main__":
  while(True):
    command = input()
    if command == 'exit':
      break
    exec(command)
  print(essay)

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
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
exit
Valid command
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
2. status: draft
Valid command
Valid command
Invalid command
grade: awaiting submission
4. number of times the grade was requested before the document was submitted: 0
Invalid command
Valid command
This Document instance has the following stats.
1. word count: 13
2. status: draft
Sample Input 1
3. grade: awaiting submission
4. number of times the grade was requested before the document was submitted: 0
essay = Document ("Roses are red")
classes ['essay'] = essay
essay_draft = Document ("Violets are blue")
classes ['essay_draft'] = essay_draft
Sample Input 3
essay.append_content(essay_draft)
another_essay_v2 = Document ("Go away Anna! Okay bye.")
essay.copy_content(another_essay_v2)
essay.key = 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).append_content(essay_draft)
essay.add_words ("Sugar is sweet and so are you")
exit
Sample Output 1
essay.key_1
essay.delete ()
essay.key = 0
Valid command
Valid command
Valid command
exit
Valid command
Sample Output 3
Valid command
Valid command
Valid command
Valid command
This Document instance has the following stats.
1. word count: 5
2. status: draft
Valid command
Valid command
Valid command
Valid command
Valid command
Valid command
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: 16
2. status: draft
3. grade: awaiting submission
4. number of times the grade was requested before the document was submitted: 0
Transcribed Image Text: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 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 exit Valid command 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 2. status: draft Valid command Valid command Invalid command grade: awaiting submission 4. number of times the grade was requested before the document was submitted: 0 Invalid command Valid command This Document instance has the following stats. 1. word count: 13 2. status: draft Sample Input 1 3. grade: awaiting submission 4. number of times the grade was requested before the document was submitted: 0 essay = Document ("Roses are red") classes ['essay'] = essay essay_draft = Document ("Violets are blue") classes ['essay_draft'] = essay_draft Sample Input 3 essay.append_content(essay_draft) another_essay_v2 = Document ("Go away Anna! Okay bye.") essay.copy_content(another_essay_v2) essay.key = 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).append_content(essay_draft) essay.add_words ("Sugar is sweet and so are you") exit Sample Output 1 essay.key_1 essay.delete () essay.key = 0 Valid command Valid command Valid command exit Valid command Sample Output 3 Valid command Valid command Valid command Valid command This Document instance has the following stats. 1. word count: 5 2. status: draft Valid command Valid command Valid command Valid command Valid command Valid command 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: 16 2. status: draft 3. grade: awaiting submission 4. number of times the grade was requested before the document was submitted: 0
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,
str . For this exercise, we will add the following attribute/s:
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:
(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.
Output 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.
Transcribed Image 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, str . For this exercise, we will add the following attribute/s: 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: (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. Output 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.
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY