Slip 21 A)
Define a class named Rectangle which can be constructed by a length and width.
The Rectangle class has a method which can compute the area and Perimeter.
Answer :
class Rectangle:
def init (self, l, w): self.length = l self.width = w
def rectangle_area(self):
return self.length*self.width newRectangle = Rectangle(12, 10) print(newRectangle.rectangle_area())
Output :
Slip 21 B)
Write a Python program to convert a tuple of string values to a tuple of
integer values.
Original
tuple values: (('333', '33'), ('1416', '55'))
New tuple
values: ((333, 33), (1416, 55))
Answer :
def Convert_Fun(tuple_str):
result = tuple((int(x[0]), int(x[1])) for x in tuple_str)
return result
tuple_str = (('333', '33'), ('1416', '55'))
print("Original tuple values:")
print(tuple_str)
print("\nNew tuple values:")
print(Convert_Fun(tuple_str))
Output :
No comments:
Post a Comment