Question

USE PYTHON CODING ####################### ## ## Definition for the class Pet ## ######################## class Pet: owner=""...

USE PYTHON CODING

#######################

##

## Definition for the class Pet

##

########################

class Pet:

owner=""

name=""

alive=False

def __init__(self,new_name):

self.name=new_name

self.alive=True

Using the code shown above as a base write a code to do the following:

- Create a separate function (not part of the class) called sameOwner which reports whether two pets have the same owner. test it to be sure it works

- Add a variable age to Pet() and assign a random value between 1 and 7 to age when a Pet object is created

- Override the >, < and == functions so that Pets can be compared on their ages. Demonstrate the working of these functions

- Define a separate function findOldest which when passed a list of Pet objects returns the name and age of the oldest pet

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
USE PYTHON CODING ####################### ## ## Definition for the class Pet ## ######################## class Pet: owner=""...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 9p This is for Python I need help. Pet #pet.py mName mAge class Pet: + __init__(name,...

    9p This is for Python I need help. Pet #pet.py mName mAge class Pet: + __init__(name, age) + getName + getAge0 def init (self, name, age): self.mName = name self.mAge = age Dog Cat def getName(self): return self.mName mSize mColor + __init__(name, age,size) + getSize() + momCommento + getDog Years() +_init__(name, age,color) + getColor + pretty Factor + getCatYears def getAge(self): return self.mAge #dog.py import pet #cat.py import pet class Dog (pet. Pet): class Cat (pet. Pet): def init (self,...

  • Need help finishing this code # Description : The Pet class contains fields for name, pet...

    Need help finishing this code # Description : The Pet class contains fields for name, pet # type,and age. The age field is the age now # or age of pet when it passed away. (These # are all dogs I have had.) There is a static or # class variable called number_pets that # tracks how many instances have been created. # The constructor will fill all fields and add # one to the number_pets variable. # The special...

  • Betty B. is writing a script for her animation. She chose Python as she has heard...

    Betty B. is writing a script for her animation. She chose Python as she has heard it's an easy language to use but is already having difficulties. Can you help her with her code? What is her problem and how can you fix it? def AnimationCharacter(): def __init__(self, name): self.name = name class Gupty(AnimationCharacter): def __init__(self): super().__init__("Gupty") class Roland(AnimationCharacter): def __init__(self): super().__init__("Roland Rabbit")

  • PYTHON 3.8 class student(): def __init__(self, name = 'Bill', grade = 9, subjects = ['math','science']): self.name...

    PYTHON 3.8 class student(): def __init__(self, name = 'Bill', grade = 9, subjects = ['math','science']): self.name = name self.grade = grade self.subjects = subjects   def add_subjects(self):       print('Current subjects:')       print(self.subjects)       more_subjects = True       while more_subjects == True:           subject_input = input('Enter a subject to add: ')           if subject_input == '':               more_subjects = False               print(self.subjects)           else:               self.subjects.append(subject_input)               print(self.subjects) m = student()...

  • How to convert this python to c++? class SOMENode: def __init__(self, name, parent, verbose=False): self.name =...

    How to convert this python to c++? class SOMENode: def __init__(self, name, parent, verbose=False): self.name = name self.parent = parent self.children = [] if self.parent: self.parent.add_child(self) self.verbose = verbose

  • Score Analysis creating a class named "Student" in python and use matplotlib package

    class students:       count=0       def __init__(self, name):           self.name = name           self.scores = []           students.count = students.count + 1       def enterScore(self):                     for i in range(4):                 m = int(input("Enter the marks of %s in %d subject: "%(self.name, i+1)))                self.scores.append(m)             def average(self):                 avg=sum(self.scores)/len(self.scores)                           return avg               def highestScore(self):                           return max(self.scores)         def display(self):                          print (self.name, "got ", self.scores)                      print("Average score is ",average(self))                          print("Highest Score among these courses is",higestScore(self))          name = input("Enter the name of Student:")  s = students(name)  s.enterScore()  s.average()  s.highestScore()  s.display()So I need to print two things, first one is to compute the average score of these courses and second one is to print out the course name with the highest score among these courses. Moreover I need to import matplotlib.pyplot as plt to show the score figure. I barely could pull the code this...

  • Using Python you will create a simple class pet which will contain: Type of pet (a...

    Using Python you will create a simple class pet which will contain: Type of pet (a string) Name of pet(a string) Age of pet (an int) Tricks (a list of tricks the pet can perform) Fleas of pet (an int) All of these data attributes except for the last one (fleas) will be unique to each object. The fleas will be common to all pets, as they like to travel. In your main part of your program, you will create...

  • Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Ini...

    Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Initialize the object properties def __init__(self, id, name, mark): # TODO # Print the object as an string def __str__(self): return ' - {}, {}, {}'.format(self.id, self.name, self.mark) # Check if the mark of the input student is greater than the student object # The output is either True or False def is_greater_than(self, another_student): # TODO # Sort the student_list # The output is the sorted...

  • Below is Python code for logic gates. It is written for a specific Circuit. Do the...

    Below is Python code for logic gates. It is written for a specific Circuit. Do the following: 1) Fill in the appropriate If , Else statement for the OrGate ( Look at the AndGate for a hint ) 2) Create two new objects, the NandGate and the NorGate classes. 3) Look at the AndGate class. What does this class inherit and use from the BinaryGate class? class LogicGate: def __init__(self,n): self.name = n self.output = None def getName(self): return self.name...

  • QUESTION 31 The tkinter command _____ kicks off the GUI event loop. goloop() doloop() mainloop() loopDloop()...

    QUESTION 31 The tkinter command _____ kicks off the GUI event loop. goloop() doloop() mainloop() loopDloop() 2.5 points    QUESTION 32 Which of the following statements about superclasses and subclasses is true? A subclass is not connected to a super class in any way A superclass inherits from a subclass. A superclass extends a subclass. A subclass extends a superclass. 2.5 points    QUESTION 33 Pickled objects can be loaded into a program from a file using the function ____....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT