Question: PYTHON 3.6 Question: (Extend to the given code below) Add a method in the Dog class called friends and initialize this in the __init__method. Create
PYTHON 3.6
Question: (Extend to the given code below)
Add a method in the Dog class called friends and initialize this in the __init__method.
Create a method called makeFriends which will take a dog object as an input and will add this dog object in the list friends if it is already not in the list.
It will also print that the dog object made a new friend or the taht the dog object is already in the friend list.
Code:
class Dog: """ Dog class definition """
species = "Canis familiaris" def __init__(self, _name, _breed): self.name = _name self.breed = _breed self.tricks = []
def teach(self, trick): self.tricks.append(trick) print(self.name + " knows " + trick)
def knows(self, chkStr): if chkStr in self.tricks: print("Yes, " + self.name + " knows " + chkStr) else: print("No, " + self.name + " doesn't know " + chkStr)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
