Task: Define a member method print_all() for class PetData. Make use of the base class' print_all() method. Sample output for the given program with inputs: 'Fluffy' 5 4444 Name: Fluffy Age: 5 ID: 4444
The first error was that there was no newline after ID: 4444. When I fixed that, I started getting the word NONE before ID:. If I knew where it was coming from I could probably figure it out, but I've got nothing. PLEASE HELP!!!
class AnimalData:
def __init__(self):
self.full_name = ''
self.age_years = 0
def set_name(self, given_name):
self.full_name = given_name
def set_age(self, num_years):
self.age_years = num_years
# Other parts omitted
def print_all(self):
print('Name:', self.full_name)
print('Age:', self.age_years)
class PetData(AnimalData):
def __init__(self):
AnimalData.__init__(self)
self.id_num = 0
def set_id(self, pet_id):
self.id_num = pet_id
# FIXME: Add print_all() member method
""" Your solution goes here"""
user_pet = PetData()
user_pet.set_name(input())
user_pet.set_age(int(input()))
user_pet.set_id(int(input()))
user_pet.print_all()```
I've been working on this assignment for 2 days and I'm getting errors no matter what I try. At one point the word NONE was randomly appearing before ID: 4444, still can't figure out where it's coming from. PLEASE HELP!!!!
Here is some of what I've tried and the errors I got.
##
No newline after ID: 4444
def print_all(self):
AnimalData.print_all(self)
print('ID:', self.pet_id)
##
ID number not showing in output.
def print_all(self):
print(AnimalData.print_all(self), 'ID:', self.id_num)
##
No newline after ID: 4444
user_pet = PetData()
user_pet.set_name("Fluffy")
user_pet.set_age(5)
user_pet.set_id(4444)
user_pet.print_all()
The correct answer is:
def print_all(self):
AnimalData.print_all(self)
print('ID:', self.id_num)
Thanks for your help @chepner!!