Question: Use python language The code below contains a Chatbot class. A Chatbot is an object that can engage in rudimentary conversation with a human. You
Use python language
The code below contains a Chatbot class. A Chatbot is an object that can engage in rudimentary conversation with a human. You will be asked to define a subclass that inherits from this Chatbot superclass.
First, run the code below to talk to the chatbot. Then look over the code to make sure you understand it.
Class Chatbot:
2
""" An object that can engage in rudimentary conversation with a human. """
3
4
def __init__(self, name):
5
self.name = name
6
7
def greeting(self):
8
""" Returns the Chatbot's way of introducing itself. """
9
return "Hello, my name is " + self.name
10
11
def response(self, prompt_from_human):
12
""" Returns the Chatbot's response to something the human said. """
13
return "It is very interesting that you say: '" + prompt_from_human + "'"
14
15
16
# TODO define a class called BoredChatbot
17
Your job is to make a subclass called BoredChatbot that inherits from Chatbot, but acts a little differently, in the following way:
A bored chatbot has a short attention span. When the human says something that is longer than 20 characters, it should respond by saying:
zzz... Oh excuse me, I dozed off reading your essay.
If, on the other hand, the human says something with a length of 20 characters or less, then the bored chatbot should respond just like a normal chatbot would.
Note that we are requiring you to use inheritance. Your new BoredChatbot class must be a subclass of the Chatbot class, and your subclass should only implement the things that make it distinct. (See the Inheritance chapter for a review of how this works.)
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
