Chapter 11 Answers For Find The Output and Error
Chapter 11 Answers For Find The Output and Error
class Point:
self.x = x
self.y = y
def __abs__(self):
def display(self):
print(self.x, self.y)
P1 = Point(12, 25)
P2 = Point(21, 45)
Print(abs(P2))
P1 = P1+ P2
P1.display()
Ans. 49.6588360717
33 70
2.
class A(object):
self.num = num
class B(object):
self.num = num
print(A(5) == B(5))
Ans. True
3.
class Circle:
self.__radius = radius
def getRadius(self):
return self.__radius
def area(self):
C1 = Circle(5)
C2 = Circle(9)
C3 = C1 + C2
print("RADIUS : ",C3.getRadius())
Ans.
RADIUS : 14
AREA : 615.44
4.
class Circle:
self.__radius = radius
def __str__(self):
C1 = Circle(5)
C2 = Circle(9)
print(C1)
print(C2)
Ans.
C1 < C2 : True
C2 > C1 : False
5.
class One:
def __init__(self):
num = 10
if isinstance(T, One):
return True
else:
return NotImplemented
class Two:
def __init__(self):
num = 100
print(One() == Two())
Ans. False
6.
class A:
def __bool__(self):
return True
X = A()
if X:
print('yes')
Ans. yes
7.
class String(object):
self.val = val
S1 = String("Hello")
S2 = String("World")
print(S1 + S2)
print(S1 - S2)
Ans.
Hello....World
Not Implemented
8.
class String(object):
self.val = val
def __str__(self):
return self.val
def __repr__(self):
S = String("Hi")
print(str(S))
Ans.
Hi
9.
class A:
def __len__(self):
return 0
X = A()
if not X:
print('no')
else:
print('yes')
Ans. no
10.
class A:
def __init__(self):
self.str = "abcdef"
return self.str[i]
x = A()
for i in x:
print(i,end=" ")
Ans. a b c d e f
11.
class A:
str = "Hi"
X = A()
1. class Matrix:
def __init__(self):
Mat = []
self.number = number
def display(self):
print(self.number)
M1 = Matrix()
M1.setValue(([1,2],[3,4]))
M2 = Matrix()
M2.setValue(([5,6],[2,3]))
M3 = Matrix()
M3 = M1 + M2
M3.display()
Ans. TypeError: unsupported operand type(s) for +: 'Matrix' and 'Matrix'
2. class A(object):
self.num = num
class B(object):
self.val = val
print(A(5) == B(5))
Ans. AttributeError: 'B' object has no attribute 'num'
3. class Point:
self.x = x
self.y = y
P1 = Point(3, 4)
print(2*P1)
Ans. TypeError: unsupported operand type(s) for *: 'int' and 'Point'
4. class String(object):
self.val = val
S1 = String("Hello")
print(S1[5])
Ans. TypeError: 'String' object does not support indexing
5. class Number:
self.num = num
return Number(self.num - N)
x = Number(4)
y = x-4
6. class A:
def __init__(self):
self.str = "abcdef"
self.str[i] = val
x = A()
x[2] = 'X'
Ans. TypeError: 'str' object does not support item assignment