Anu3.2 (Python)
Anu3.2 (Python)
Procedure:
Source Code:
class Student:
def init (self, student_id, student_name):
self.student_id = student_id
self.student_name = student_name
self.student_class = "612 A"
student1 = Student("john Doe") print
(student1.student_id)
print (student1.student_name)
print (student1.student_class)
del student1.student_name
print(student1.student_id)
print (student1.student_class)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output:
2. Write a Python class to find a pair of elements (indices of the two numbers)
from a given array whose sum equals a specific target number.
Source Code:
Output:
3. Write a Python class named Rectangle constructed by a length and width and a
method which will compute the area of a rectangle
Source Code:
class rectangle:
def init (self, length , breadth):
self.length = length
self.breadth = breadth
def area (self):
return self.length * self.breadth
r = rectangle(6,9)
area = r.area()
print (area)
Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Write a Python class named Circle constructed by a radius and two methods
which will compute the area and the perimeter of a circle
Source Code:
class circle:
def init (self, r):
self.r = r
def area (self):
return 3.14 * self.r ** 2
def perimeter (self):
return 2 * 3.14 * self.r
a = circle (5)
area = a.area()
perimeter = a.perimeter()
print (area)
print (perimeter)
Output:
5. Write a Python program to create two empty classes, Student and Marks. Now
create some instances and check whether they are instances of the said classes
or not. Also, check whether the said classes are subclasses of the built-in
object class or not
Source Code:
class student:
pass
class marks:
pass
student1 = student()
marks1 = marks()
print (isinstance(student1,student))
print (isinstance(marks1,marks))
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output: