Question: Copy the following Python code into a new, blank Python file in Spyder. Save this new file as animals.py import datetime class Animal: def _

Copy the following Python code into a new, blank Python file in Spyder. Save this new file as animals.py
import datetime
class Animal:
def __init__(self, species, name, gender, birth_year):
self.species = species
self.name = name
self.gender = gender
self.birth_year = birth_year
def age(self):
now = datetime.datetime.now()
current_year = now.year
return( current_year - self.birth_year )
def __repr__(self):
return('Hello I am a '+ str(self.species)+' named '+ self.name +' and I am '+ str(self.age())+" years old")
class Dog(Animal):
def __init__(self, name, gender, birth_year, breed):
super().__init__('Dog', name, gender, birth_year)
self.breed = breed
def __repr__(self):
return("Hello I am a dog named "+ self.name +". I'm an "+ self.breed +" and I'm "+ str(self.age())+" years old")
def fetch(self, distance):
print("RuffRuff: I fetched a stick thrown "+ str(distance)+" yards. I ran a total of "+ str(distance *2)+" yards there and back.")
class Cat(Animal):
def __init__(self, name, gender, birth_year, breed):
super().__init__("Cat", name, gender, birth_year)
self.breed = breed
def purr(self):
str =""",__,
|\"\\___//|
|=66=|
\=._Y_.=/
)`(
/\((
||))
/||||\_//
\||._.||/-`
'"''"'"""
print(str)
Once you copied it, run the file. Did it run? If not, you may have copied it incorrectly.
Yes
No

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!