How to do these two using python Add method distance to the

How to do these two using python? Add method distance() to the class Point. It makes another Point object as input and returns the distance to that point (from the point invoking the method). Gg c = Point() Gg c.setx(0) c.sety(1) Gg d = Point() Gg d.setx(1) Gg d.sety(0) Gg c.distance (d) 1.4142135623730951 Perkovic 8.13, 1st ed. Add to class Animal methods setAge() and getAge() to set and retrieve the age of the Animal object. Gg flipper = Animal() Gg flipper.setSpecies (\"dolphin\") Gg flipper.getAge(3) Gg flipper.getAge() 3

Solution

class Point:
def __init__(setting,x=0,y=0):## setting values default values are 0,0
setting.x=x
setting.y=y
def distance(setting):## returning distance
return ((setting.x**2)+(setting.y**2))**0.5

############# Question-2

class Animal:
def __init__(self, setSpecies=\"\", setAge=0):
self.setSpecies = setSpecies
self.setAge = setAge
def getAge(self):
return self.setAge

 How to do these two using python? Add method distance() to the class Point. It makes another Point object as input and returns the distance to that point (from

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site