0% found this document useful (0 votes)
13 views3 pages

Ies 3 .

The document defines a parent Shape class with area and perimeter methods that are not defined, then defines Square, RightAngledTriangle, and SemiCircle subclasses that inherit from Shape and override the area and perimeter methods with specific calculations for each shape. It then creates instances of each subclass, calls their area and perimeter methods, and prints the results.

Uploaded by

Shubham Bayas
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)
13 views3 pages

Ies 3 .

The document defines a parent Shape class with area and perimeter methods that are not defined, then defines Square, RightAngledTriangle, and SemiCircle subclasses that inherit from Shape and override the area and perimeter methods with specific calculations for each shape. It then creates instances of each subclass, calls their area and perimeter methods, and prints the results.

Uploaded by

Shubham Bayas
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/ 3

ISE 3

Shubham Bayas

B_66

Q1
import math
# Parent class Shape
class Shape:
def area(self):
pass

def perimeter(self):
pass

# Subclass Square
class Square(Shape):
def __init__(self, side_length):
self.side_length = side_length

def area(self):
return self.side_length ** 2

def perimeter(self):
return 4 * self.side_length

# Subclass RightAngledTriangle
class RightAngledTriangle(Shape):
def __init__(self, base, height, hypotenuse):
self.base = base
self.height = height
self.hypotenuse = hypotenuse

def area(self):
return 0.5 * self.base * self.height

def perimeter(self):
return self.base + self.height + self.hypotenuse

# Subclass SemiCircle
class SemiCircle(Shape):
def __init__(self, radius):
self.radius = radius

def area(self):
return 0.5 * math.pi * (self.radius ** 2)

def perimeter(self):
return math.pi * self.radius

# Create objects and calculate area/perimeter

# Square
square = Square(3)
print("Square - Area:", square.area())
print("Square - Perimeter:", square.perimeter())

# Right-angled Triangle
triangle = RightAngledTriangle(3, 4, 5)
print("Right-Angled Triangle - Area:", triangle.area())
print("Right-Angled Triangle - Perimeter:", triangle.perimeter())
ISE 3
Shubham Bayas

B_66

# Semi-circle
semicircle = SemiCircle(10)
print("Semi-circle - Area:", semicircle.area())
print("Semi-circle - Perimeter:", semicircle.perimeter())

Output :-
ISE 3
Shubham Bayas

B_66

Q2
input_file = 'TestFile1.txt'
output_file = 'TestFile2.txt'
def replace_word(input_file, output_file):
with open(input_file, 'r') as file:
content = file.read()

modification = content.replace('is', 'was')

with open(output_file, 'w') as file:


file.write(modification)

replace_word(input_file, output_file)

Output :-

You might also like