Question

In Python Exercise – Overriding class Address: def __init__(self, street, num):     self.street_name = street    ...

In Python

Exercise – Overriding

class Address:

def __init__(self, street, num):

    self.street_name = street

    self.number = num

Now make a subclass of the class Address called CampusAddress that has a new attribute, office number, that can vary. This subclass will always have the street attribute set to Massachusetts Ave and the num attribute set to 77. Use the class as follows:

>>> Sarina_addr = CampusAddress("32-G904")

>>> Sarina_addr.office_number

’32G-904’

>>> Sarina_addr.street_name

’Massachusetts Ave’

>>> Sarina_addr.number

77

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Given below is the code for the question. PLEASE MAKE SURE INDENTATION IS EXACTLY AS SHOWN IN IMAGE.
Please do rate the answer if it helped. Thank you.

class Address:
   def __init__(self, street, num):
       self.street_name = street
       self.number = num

class CampusAddress(Address):
   def __init__(self, off_num):
       Address.__init__(self, "Massachusetts Ave", 77)
       self.office_number = off_num


Sarina_addr = CampusAddress("32-G904")
print(Sarina_addr.office_number)
print(Sarina_addr.street_name)
print(Sarina_addr.number)

Add a comment
Know the answer?
Add Answer to:
In Python Exercise – Overriding class Address: def __init__(self, street, num):     self.street_name = street    ...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python: Which keyword should be replaced instead of X? class Class(Car): def __init__ (self,arg1,arg2): X.__init__(arg1,arg2)...

    In Python: Which keyword should be replaced instead of X? class Class(Car): def __init__ (self,arg1,arg2): X.__init__(arg1,arg2) Question 21 options: class def super() super

  • In PYTHON: Assume there is a class Animal, containing a method with the header: def __init__(self)....

    In PYTHON: Assume there is a class Animal, containing a method with the header: def __init__(self). What statement will create an Animal object and store it in the variable 'cat'.

  • PYTHON -------------------------------------------------------- class LinkedList:    def __init__(self):        self.__head = None        self.__tail = None   

    PYTHON -------------------------------------------------------- class LinkedList:    def __init__(self):        self.__head = None        self.__tail = None        self.__size = 0    # Return the head element in the list    def getFirst(self):        if self.__size == 0:            return None        else:            return self.__head.element        # Return the last element in the list    def getLast(self):        if self.__size == 0:            return None        else:            return self.__tail.element    # Add an element to the beginning of the list    def addFirst(self, e):        newNode = Node(e) # Create a new node        newNode.next = self.__head # link...

  • in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Po...

    in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Pop(self): return self.items.pop() def Display(self): for i in reversed(self.items): print(i,end="") print() s = My_Stack() #taking input from user str = input('Enter your string for palindrome checking: ') n= len(str) #Pushing half of the string into stack for i in range(int(n/2)): s.Push(str[i]) print("S",end="") s.Display() s.Display() #for the next half checking the upcoming string...

  • Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def...

    Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def __init__(self, make, model, year) Methods in BMW parent class (can leave as method stubs for now): startEngine() -must print "The engine is now on." stopEngine() -must print "The engine is now off." Make another class called ThreeSeries -Must inherit BMW Hint: class ThreeSeries(BMW): -Also passes the three attributes of the parent class and invoke parent Hint: BMW.__init__(self, cruiseControlEnabled, make, model, year) -Constructor must have...

  • Here is a Python program. import turtle class Box:     def __init__(self, x, y, width, height):...

    Here is a Python program. import turtle class Box:     def __init__(self, x, y, width, height):         self.x = x         self.y = y         self.width = width         self.height = height     def show(self):         turtle.up()         turtle.goto(x, y)         turtle.down()         for _ in range(2):             turtle.forward(width)             turtle.right(90)             turtle.forward(height)             turtle.right(90) bigbox = Box(-100, -150, 200, 300) bigbox.show() turtle.done() If you run the above program, it will produce an error. What is the keyword that has...

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

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

  • # Declaring Node class class Node: def __init__(self, node_address): self.address = node_address self.next = None #...

    # Declaring Node class class Node: def __init__(self, node_address): self.address = node_address self.next = None # Creating empty list forwarding_list = Node() # Recurssive Method for add address def addAddress(node): if node.address == old_address: # Address is same if node.next == None: # Next is None node.next = Node(new_address) # Add Next print("Added") # Addedd else: # Next is not none print("Entry already exists") elif node.next != None: # Check Next Node addAddress(node.next, old_address, new_address) def addEntry(forwarding_list):# Method for add...

  • class BinaryTree: def __init__(self, data, left=None, right=None): self.__data = data self.__left = left self.__right = right...

    class BinaryTree: def __init__(self, data, left=None, right=None): self.__data = data self.__left = left self.__right = right def insert_left(self, new_data): if self.__left == None: self.__left = BinaryTree(new_data) else: t = BinaryTree(new_data, left=self.__left) self.__left = t def insert_right(self, new_data): if self.__right == None: self.__right = BinaryTree(new_data) else: t = BinaryTree(new_data, right=self.__right) self.__right = t def get_left(self): return self.__left def get_right(self): return self.__right def set_data(self, data): self.__data = data def get_data(self): return self.__data def set_left(self, left): self.__left = left def set_right(self, right): self.__right...

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