Question
I need help fixing my code. IN PYTHON 3. I'll post pictures and copy my code below. I will also provide pics of the problems
I need help fixing my code. IN PYTHON 3. I'll post pictures and copy my code below. I will also provide pics of the problems I am having.
>
import pet
pet_list = [] while True: pet_owner = input("Please enter owner's name: ") pet.Pet.pet_owner = pet_owner if pet_owner == 'q' or pet_owner == 'Q': break pet_name = input("Please enter the pet's name: ") age = int(input("Please enter the pet's age: ")) flop=0 house=input("Is the dog house-broken? ") beag=input("Is the dog a beagle? ") if(beag=='y'): flop=int(input("How floppy are the ears? "))
else: pet_d=pet.Dog(pet_name,age) pet_list.append(pet_d) continue pet_d = pet.Beagle(pet_name, age,house,flop) pet_list.append(pet_d) print("Dog List:") for pet in pet_list: print(pet)
>
class Pet: pet_owner = "X" def __init__(self, name, age): self.pet_name = name self.pet_age = age
def __str__(self): output = "{0} is {1} year(s) old and is owned by {2}".format(self.pet_name, self.pet_age, Pet.pet_owner) return output
class Dog(Pet): house=False def __init__(self,dog_name="Spot",dog_age=1): self.dog_name=dog_name self.dog_age=dog_age
def __str__(self): output="Dog {0} is {1} year(s) old, is owned by {2}".format(self.dog_name,self.dog_age,self.pet_owner) if self.house: output+=", and is house-broken" else: output+=", and is not house-broken" return output
def set_house(self,val): self.house=val
class Beagle(Dog): flop=0
def __init__(self,bg_name="Ace",bg_age=3,bg_house="yes",bg_flop=2): self.bg_name=bg_name self.bg_age=bg_age self.bg_house=bg_house self.bg_flop=bg_flop
def __str__(self): output="Beagle {0} is {1} year(s) old, is owned by {2}".format(self.bg_name,self.bg_age,self.pet_owner) if self.bg_house=="yes": output+=", is not house-broken" else: output+=", is house-broken" output+=", and has an ear floppiness of "+str(self.bg_flop) return output def set_flop(self, flop): self.bg_flop = flop
>
>
>
>
Please enter the owner's name: Debbie Please enter the pet's name: Max Please enter the pet's age: 4 Is the dog house-broken? y Is the dog a beagle? n Please enter the owner's name: Louis Please enter the pet's name: Prince Please enter the pet's age: 2 Is the dog house-broken? n Is the dog a beagle? y How floppy are the ears? 7 Please enter the owner's name: Janice Please enter the pet's name: Newton Please enter the pet's age: 8 Is the dog house-broken? n Is the dog a beagle? n Please enter the owner's name: Q Dog List: Dog Max is 4 year(s) old, is owned by Debbie, and is house-broken Beagle Prince is 2 year(s) old, is owned by Louis, is not house-broken, and has an ear floppiness of 7 Dog Newton is 8 year(s) old, is owned by Janice, and is not house-broken
> (I will bold the differences)
Please enter the owner's name: Debbie Please enter the pet's name: Max Please enter the pet's age: 4 Is the dog house-broken? y Is the dog a beagle? n Please enter the owner's name: Louis Please enter the pet's name: Prince Please enter the pet's age: 2 Is the dog house-broken? n Is the dog a beagle? y How floppy are the ears? 7 Please enter the owner's name: Janice Please enter the pet's name: Newton Please enter the pet's age: 8 Is the dog house-broken? n Is the dog a beagle? n Please enter the owner's name: Q Dog List: Dog Max is 4 year(s) old, is owned by Q, and is house-broken Beagle Prince is 2 year(s) old, is owned by Q, is not house-broken, and has an ear floppiness of 7 Dog Newton is 8 year(s) old, is owned by Q, and is not house-broken
>
import pet 7 pet_list = [] 8 while True: pet_owner = input("Please enter owner's name: ") pet.Pet.pet_owner = pet_owner 11 12 13 if pet_owner == 'q' or pet_owner == '': break pet_name = input("Please enter the pet's name: ") age = int(input("Please enter the pet's age: ")) 14 15 16 1 flop=0 house=input("Is the dog house-broken?") beag=input("Is the dog a beagle?") if(beag=='y'): floprint(input("How floppy are the ears? ")) 20 21 22 23 24 else: pet_d=pet. Dog(pet_name, age) pet_list.append(pet_d) continue 25 26 27 28 pet_d = pet. Beagle(pet_name, age, house, flop) 29 pet_list.append(pet_d) print("Dog List:") 31 for pet in pet list: 32 print(pet) 33 5 class Pet: pet_owner = "X" Bovou def init__(self, name, age): self.pet_name = name self.pet_age = age def __str_(self): output = "{0} is {1} year(s) old and is owned by {2}".format(self.pet_name, self.pet_age, Pet.pet_owner) return output 16 class Dog(Pet): house=False 17 def __init__(self, dog_name="Spot", dog_age=1): self.dog_name=dog_name self.dog_age=dog_age def str_(self): output="Dog {0} is {1} year(s) old, is owned by {2}".format(self.dog_name, self.dog_age, self.pet_owner) if self.house: output+=", and is house-broken" else: output==", and is not house-broken" return output def set_house(self, val): self.house-val 37 class Beagle (Dog): flop=0 def __init__(self, bg_name="Ace", bg_age=3, bg_house="yes", bg_flop=2): self.bg_name=bg_name self.bg_age=bg_age self.bg_house=bg_house self.bg_flop=bg_flop def __str_(self): output="Beagle {0} is {1} year(s) old, is owned by {2}".format(self.bg_name,self.bg_age, self.pet_owner) if self.bg_house--"yes" output+=", is not house-broken" else: output", is house-broken" output+-", and has an ear floppiness of "+str(self.bg_flop) return output def set_flop (self, flop) : self.bg_flop - flopStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started