0% found this document useful (0 votes)
67 views7 pages

Anmol 2K18CSUN01054 Btech Cse 4B: Manav Rachna University, Faridabad

The document contains a lab assignment on object-oriented programming in Python. It includes 5 problems: 1) Create a Triangle class with methods to create and print sides of a triangle, 2) Create a class to get user input and print a string, 3) Create a Rectangle class that takes length and width and computes perimeter, 4) Create a Circle class that takes a radius and computes area and perimeter, 5) Demonstrate multiple inheritance with four classes. Solutions for each problem are provided as code snippets.

Uploaded by

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

Anmol 2K18CSUN01054 Btech Cse 4B: Manav Rachna University, Faridabad

The document contains a lab assignment on object-oriented programming in Python. It includes 5 problems: 1) Create a Triangle class with methods to create and print sides of a triangle, 2) Create a class to get user input and print a string, 3) Create a Rectangle class that takes length and width and computes perimeter, 4) Create a Circle class that takes a radius and computes area and perimeter, 5) Demonstrate multiple inheritance with four classes. Solutions for each problem are provided as code snippets.

Uploaded by

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

ANMOL

2K18CSUN01054
BTECH CSE 4B

MANAV RACHNA UNIVERSITY, FARIDABAD


Department of Computer Science and Technology

Course: B.Tech

Subject: Programming for Problem Solving using Python(CSW208B)

Lab 9
Learning Outcome CO1: Student will be able to implement concepts of
OOPS.
1. Write a Python program that create a class tringle and define two
methods, create_triangle() and print_sides().

2. Write a Python program to create a class with two methods inputstr()


and printstr().

3. Write a Python program to create a class Rectangle that takes the


parameter length and width. The class should also contain a method for
computing its perimeter.

4.  Write a Python program to create a class Circle that takes the
parameter radius. The class should also contain two methods for
computing its area & perimeter respectively.

5. Write a Python program to demonstrate multiple Inheritance.


#1

class triangle:

a=9

b=8

c=7

st="Triangle created"

def create_triangle(self):

print(self.st)

def print_side(self):

print(self.a)

print(self.b)

print(self.c)

z=triangle()

z.print_side()

z.create_triangle()
#2

class IOString():

def __init__(self):

self.str1 = ""

def input_String(self):

self.str1 = input()

def print_String(self):

print(self.str1)

str1 = IOString()

str1.input_String()
str1.print_String()

#3

class rectangle():

def __init__(self,breadth,length):

self.breadth=breadth

self.length=length

def area(self):

return self.breadth*self.length

a=int(input("Enter length of rectangle: "))

b=int(input("Enter breadth of rectangle: "))

obj=rectangle(a,b)

print("Area of rectangle:",obj.area())
#4

class Circle():

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))

z = Circle(8)

print("Area of circle is : ",z.area())

print("Perimeter of circle is : ",z.perimeter())


#5

class Class1:

def m(self):

print("In Class1")

class Class2(Class1):

def m(self):

print("In Class2")

class Class3(Class1):

def m(self):

print("In Class3")

class Class4(Class2, Class3):

def m(self):

print("In Class4")
obj = Class4()

obj.m()

Class2.m(obj)

Class3.m(obj)

Class1.m(obj)

You might also like