WORKSHEET 3.
Student Name: Abdul Samad Khan                                      UID: 21BCS1843
Branch: CSE                                                         Section/Group: 604 A
Semester: 4th                                                       Date of Performance: 9/05/2023
Subject Name: Programming in Python Lab                             Subject Code: 21CSP-259
Aim:
WAP On the basis of learning write and give the output of the followings programs:
    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
    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.
    3. Write a Python class named Rectangle constructed by a length and width and a method which will
       compute the area of a rectangle
    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
    5. Write a Python program to crate 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:
1. class
Student:
   student_id = 7093
student_name = "Shashi"
print("Original") for attr, value in Student.
dict .items():
   if not attr.startswith('_'): print(f'{attr}
->      {value}')         print("After
        adding") Student.student_class = 'V'
for attr, value in Student. dict .items():
   if not attr.startswith('_'):
print(f'{attr} -> {value}')
print("After removing ")
Abdul Samad Khan                                                                              21BCS1843
del Student.student_name for attr, value in
Student. dict .items(): if not
attr.startswith('_'):   print(f'{attr} ->
{value}')
Output:
2.
class pairs: def twoSum(self,
nums, target): lookup = {} for i,
num in enumerate(nums):
if target - num in lookup: return
          (lookup[target - num], i )
lookup[num] = i
print("index1=%d, index2=%d" %
pairs().twoSum((10,20,10,40,50,60,70),50)
)
Output:
3.      class
Rectangleconc():
def init (self, l, w):
self.length = l
      self.width = w
  def rectangle_area(self): return
self.length*self.width
Abdul Samad Khan                              21BCS1843
 obj= Rectangleconc(12, 10)
 print(obj.rectangle_area())
 Output:
 4.      class
 Circleconc():     def
 init       (self, r):
 self.radius = r
      def area(self):
        return self.radius**2*3.14
   def perimeter(self):
 return 2*self.radius*3.14
 obj = Circleconc(8)
 print(obj.area())
 print(obj.perimeter())
 Output:
 5.      class
 Student: pass class
 Marks: pass
 student1 = Student() marks1 = Marks()
 print(isinstance(student1,
Student)) print(isinstance(marks1,
Student)) print(isinstance(marks1,
 Marks))
         print(isinstance(student1,
 Marks)) print("Check whether the said
 classes are
Abdul Samad Khan                         21BCS1843
subclasses of the built-in object class or not.") print(issubclass(Student,
object))
print(issubclass(Marks, object))
OUTPUT:-
Abdul Samad Khan                                                              21BCS1843