Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 21 Answers

    Write a Python program

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 :

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 21 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 21 Answers Reviewed by technical_saurabh on December 31, 2021 Rating: 5

No comments:

Powered by Blogger.