Q&A CBSE12A-2016-B01E #6277
Question:
Find and write the output of the following python code:
class Book:
def __init__(self,N=100,S="Python"): #constructor
self.Bno=N
self.BName=S
def Assign(self, N,S):
self.Bno= self.Bno + N
self.BName= S + self.BName
def ShowVal(self):
print(self.Bno,"#",self.BName)
s=Book()
t=Book(200)
u=Book(300,"Made Easy")
s.ShowVal()
t.ShowVal()
u.ShowVal()
s.Assign(5, "Made ")
t.Assign(15,"Easy ")
u.Assign(25,"Made Easy")
s.ShowVal()
t.ShowVal()
u.ShowVal()
Answer:
| Python 2.7 output | Other Versions output |
|---|---|
| 100 # Python 200 # Python 300 # Made Easy 105 # Made Python 215 # Easy Python 325 # Made EasyMade Easy |
(100, ‘#’, ‘Python’) (200, ‘#’, ‘Python’) (300, ‘#’, ‘Made Easy’) (105, ‘#’, ‘Made Python’) (215, ‘#’, ‘Easy Python’) (325, ‘#’, ‘Made EasyMade Easy’) |
