0% found this document useful (0 votes)
2 views4 pages

Anu3.2 (Python)

The document outlines an experiment for a Python programming lab focused on Object Oriented Programming concepts, including classes, inheritance, and polymorphism. It includes specific tasks such as creating classes for Student, Rectangle, and Circle, along with source code examples and expected outputs. Additionally, it covers creating empty classes and checking their instances and subclasses status against the built-in object class.

Uploaded by

nsrinivasrao1945
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Anu3.2 (Python)

The document outlines an experiment for a Python programming lab focused on Object Oriented Programming concepts, including classes, inheritance, and polymorphism. It includes specific tasks such as creating classes for Student, Rectangle, and Circle, along with source code examples and expected outputs. Additionally, it covers creating empty classes and checking their instances and subclasses status against the built-in object class.

Uploaded by

nsrinivasrao1945
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


Experiment: 3.2

Name: Anurag yadav UID: 21BCS3736


Branch: CSE Section: 612 - A
Semester: 4th Date of Performance: 03 May 2023
Subject: Programming in Python Lab Subject Code: 21CSP-259

Aim: Program to implement concepts of Object Oriented Programming such as


classes, inheritance and polymorphism.

Procedure:

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

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

print (issubclass(student, object))


print (issubclass(marks,object))

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy