Question

How to write a Python program that has a base class with methods and attributes ,...

How to write a Python program that has a base class with methods and attributes , subclasses with methods and attributes. Please use any example you'd like.

Homework Answers

Answer #1
class Animal:
    def __init__(self, type, name):
        self.type = type
        self.name = name

    def getType(self):
        return self.type

    def getName(self):
        return self.name

    def setType(self, type):
        self.type = type

    def setName(self, name):
        self.name = name


class Cat(Animal):
    def __init__(self, type, name, age):
        super().__init__(type, name)
        self.age = age

    def getAge(self):
        return self.age

    def setAge(self, age):
        self.age = age

# Testing
c = Cat("type1","billy",4)
print(c.getName())

billy

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write code using python or repl.it 1. List 4 attributes that you'd create for class "student"....
write code using python or repl.it 1. List 4 attributes that you'd create for class "student". 2. List 2 setters and 2 getters for class student including their parameters 3. Write the complete definition for class student including attributes and methods created above using the correct Python syntax. 4. Create one object of class student and print the values of all its attributes. You can either call the getter method or access the attribute directly using the dot notation.
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the equivalent radix-e (another arbitrary base) number. Where e and d are members in [2, 16]: Hints: The easiest approach is - you can convert the radix-d number to decimal one first, and then convert the decimal number to the radix-e number.
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. Credit Score Annual Intrest Rate 500-649 %15.5 650-729 %9.5 730-800 %4.5 The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range, it asks him/her to enter a numeric...
Write a class Store which includes the attributes: store name and sales tax rate. Write another...
Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Book Store, which inherits from Store. A Book Store has the following additional attributes: how many books are sold every year and the average price per book. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Book Store; In the Book Store class, also code a method returning the average taxes per year....
Write a python program that calculates the area of triangle. The user will be asked to...
Write a python program that calculates the area of triangle. The user will be asked to enter the base (b) and the height (h). The formula to calculate the area is: Triangle_area=(bh)/2 Note: the program should print the area to the user: (for example: the area of the triangle is: 34.3)
in JAVA Write a class Store which includes the attributes: store name and sales tax rate....
in JAVA Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Yarn Store, which inherits from Store. A Yarn Store has the following additional attributes: how many skeins of yarn are sold every year and the average price per skein. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Yarn Store; In the Yarn Store class, also code a method returning the...
Write a Python class, Flower, that has 3 instance variables name, num_petals and price which have...
Write a Python class, Flower, that has 3 instance variables name, num_petals and price which have types str, int and float. Your class must have a constructor method to initialize the variables to an appropriate value, and methods for setting the value of each instance variable (set methods) and for retrieving the instance variable values (get methods). You can use the credit card code we looked at for assistance.
Write a Python program to create a dictionary from two lists without losing duplicate values. If...
Write a Python program to create a dictionary from two lists without losing duplicate values. If there is more values in the key list, then provided key should return an empty set if there is no match. (Hint: use defaultdict) Example: class_list = ['Class-V', 'Class-VI', 'Class-VII', 'Class-VIII','Class-IX'] id_list = [1, 2, 2, 3] Output: assuming you store the values in a data structure named temp print(temp["Class-V"]) # {1} print(temp["Class-IX"]) # set() can you please try and do on google colab
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT