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,...

  • 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()...

  • 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...

  • 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...

  • 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 ____....

  • I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to...

    I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...

  • Use your Food class, utilities code, and sample data from Lab 1 to complete the following...

    Use your Food class, utilities code, and sample data from Lab 1 to complete the following Tasks. def average_calories(foods):     """     -------------------------------------------------------     Determines the average calories in a list of foods.     foods is unchanged.     Use: avg = average_calories(foods)     -------------------------------------------------------     Parameters:         foods - a list of Food objects (list of Food)     Returns:         avg - average calories in all Food objects of foods (int)     -------------------------------------------------------     """ your code here is the...

  • Write a python program using Object Oriented and do the following: 1. create class "cat" with...

    Write a python program using Object Oriented and do the following: 1. create class "cat" with the following properties: name, age (create constructor method: def __init__) 2. create class "adopter" with the following properties: name, phone 3. create class "transaction" with these properties: adopter, cat (above objects) cat1 = "puffy, 2" adopter1 = "Joe, 123" Test your program: Joe adopts puffy. Print: "Per Transaction 1 <joe> has adopted <puffy>" this can only be done with object oriented programming, no way...

  • (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text...

    (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...

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
ADVERTISEMENT