Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help fixing my code. IN PYTHON 3. I keep getting errors, and I don't know what I'm doing wrong. I'll post my code

I need help fixing my code. IN PYTHON 3. I keep getting errors, and I don't know what I'm doing wrong. I'll post my code for main.py and pet.py (I'm working with two seperate files) as well as the expected output.

>>

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: ") pet_age = int(input("Please enter the pet's age: ")) house = input("Is the dog house-broken?") if house == 'yes' or house == 'y': doghouse = True else: dog_house = False beagle = input("Is the dog a beagle?") if beagle == 'y' or beagle == 'Y': flop = int(input("How floppy are the ears?")) beagle = pet.Beagle(pet_name, pet_age, house, flop) pet_list.append(beagle) else: dog = pet.Dog(pet_name, pet_age) dog.set_house(doghouse) pet_list.append(dog) print("Pet 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.owner_name) return output

class Dog(Pet): house = False dog_name = 'Spot' dog_age = 1 def __init__(self, name, age): self.dog_name = name self.dog_age = age def __str__(self, house): if house == False: st = "not" else: st = "" output="Dog {0} is {1} year(s) old, is owned by {2}, and is {3} house-broken".format(self.dog_name, self.dog_age, Pet.pet_owner, st) return output def set_house(self, house): self.house = house

class Beagle(Dog): bg_name = "Ace" bg_age = 3 bg_house = "yes" bg_flop = 2 def __init__(self, name, age, house, flop): self.bg_name = name self.bg_age = age self.bg_house = house self.bg_flop = flop def __str__(self, house): if house == "yes" or house == "y": st = "not" else: st = "" output = "Beagle {0} is {1} year(s) old, is owned by {2}, is {3} house-broken, and has an ear floppiness of {4}".format(self.bg_name, self.bg_age, Pet.pet_owner, st, 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'll post pictures for indention purposes.

image text in transcribed

image text in transcribed

File Edit Format Run Options Window Help 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 == '': break pet_name = input ("Please enter the pet's name: "); pet age = int(input ("Please enter the pet's age: "); house = input ("Is the dog house-broken?"), if house == 'yes' or house == 'y': doghouse = True else: dog_house = False beagle = input("Is the dog a beagle?") if beagle == 'y' or beagle == 'Y': flop = int(input ("How floppy are the ears?") beagle = pet.Beagle (pet_name, pet_age, house, flop) pet_list.append (beagle) else: dog = pet.Dog (pet name, pet age) dog.set_house (doghouse) pet list.append(dog), print("Pet List:") for pet in pet_list: print (pet) pet.py - C:\Users\dawso\AppData\Local\Programs\Python Python37-32\pet.py (3.7.4) File Edit Format Run Options Window Help 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 owner_name) return output class Dog (Pet): house = False dog_name = 'Spot' dog age = 1 def init (self, name, age): self.dog_name = name selt.dog_age = age def str (self): if house =false; st = "not" else: st - output="Dog (0) is (1) year(s) old, is owned by (2), and is (3) house-broken". format (selt.dog_name, self.dog_age, Pet.pet_owner, st) return output def set house (self, house): self house - house class Beagle (Dog) : bg_name = "Ace" bg_age = 3 bg_house = "yes" bg_flop = 2 definit (self, name, age, house, flop): self.bg_name = name self.bg_age - age self.bg_house = house self.bg_flop = flop def _str_(self): if house == "yes" or house == "y": st = "not" else: st = output = "Beagle {0} is (1) year(s) old, is owned by (2), is {3} house-broken, and has an ear floppiness of (4)". format (self.bg_name, return output def set_flop (selt, flop): self.bg_flop = flop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Progress Monitoring Data Tracking Organizer

Authors: Teacher'S Aid Publications

1st Edition

B0B7QCNRJ1

More Books

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago