How to do these two using python? Add method distance() to the class Point. It m
ID: 3941388 • Letter: H
Question
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() 3Explanation / Answer
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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.