English

Rewrite the following code after removing errors. Underline each correction and write the output after correcting the code: class First(): def __init__(self):

Advertisements
Advertisements

Question

Rewrite the following code after removing errors. Underline each correction and write the output after correcting the code:

class First():
def __init__(self):
     print "first":
class Second(object):
def __init__(self):
     print "second"
class Third(First, Second):
def __init__(self):
     First.__init__(self):
     Second.__init__(self):
     print "that's it" 
t=Third()t=Third()
Code Writing
Advertisements

Solution

class First():

def __init__(self):
     print "first"

class Second(object):

def __init__(self): 
     print "second"

class Third(First, Second):

def __init__(self): 
     First.__init__(self) 
     Second.__init__(self) 
     print "that's it"

t = Third()

Corrections:

  • def __init__(self): instead of def __init__(self): with missing/incorrect underscores
  • First.__init__(self) instead of First.__init__(self):
  • Second.__init__(self) instead of Second.__init__(self):
  • t = Third() instead of t=Third()t=Third()

Output

first
second
that's it
shaalaa.com
  Is there an error in this question or solution?
Chapter 4: Inheritance - EXERCISE [Page 81]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 4 Inheritance
EXERCISE | Q 15. | Page 81
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×