Adi 3.2 - Removed
Adi 3.2 - Removed
WORKSHEET 3.2
2. Source Code:
1. Write a Python class named Student with two attributes student_id,
student_name. Add a new attribute student_class and display the entire
attribute and their values of the said class. Now remove the student_name
attribute and display the entire attribute with values.
class Student:
def __init__(self, student_id, student_name):
self.student_id = student_id
self.student_name = student_name
def add_class(self, student_class):
self.student_class = student_class
def display_attributes(self):
attributes = vars(self)
print("Attributes and their values:")
for attr, value in attributes.items():
print(attr, ":", value)
def remove_name(self):
del self.student_name
OUTPUT:
twosum = TwoSum()
twosum.get_input()
indices = twosum.find_indices()
print(indices)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
OUTPUT:
class Rectangle:
def __init__(self):
self.length = 0
self.width = 0
def get_input(self):
self.length = float(input("Enter the length: "))
self.width = float(input("Enter the width: "))
def area(self):
return self.length * self.width
rectangle = Rectangle()
rectangle.get_input()
print("The area of the rectangle is:", rectangle.area())
OUTPUT:
circle = Circle()
circle.get_input()
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
print("The area of the circle is:", circle.area())
print("The perimeter of the circle is:", circle.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.
class Student:
pass
class Marks:
pass
student1 = Student()
student2 = Student()
marks1 = Marks()
marks2 = Marks()
print(isinstance(student1, Student))
print(isinstance(student2, Student))
print(isinstance(marks1, Marks))
print(isinstance(marks2, Marks))
print(issubclass(Student, object))
print(issubclass(Marks, object))
Output