Commit f2ebfddb by mohammed.shibili

completed

parents
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (assignment1)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/assignment1.iml" filepath="$PROJECT_DIR$/.idea/assignment1.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
from shapes import square
from shapes import rectangle
from shapes import circle
while True:
# selecting shape by user
print("1.square \n 2.rectangle \n 3.circle \n")
shape = int(input("enter your choice\n"))
# Exception raise for wrong choice
if shape > 4 or shape < 0:
raise Exception("invalid choice of shape")
# calling for calculation
if shape == 1:
side = float(input("enter side length"))
square.Area(side).square_area()
square.Perimeter(side).square_perimeter()
elif shape == 2:
length = float(input("enter the length"))
breadth = float(input("enter the breadth"))
rectangle.Area(length, breadth).rectangle_area()
rectangle.Perimeter(length, breadth).rectangle_perimeter()
elif shape == 3:
radius = float(input("enter the radius"))
circle.Area(20).circle_area()
circle.Perimeter(20).circle_perimeter()
# inheriting exception class
class Check(Exception):
pass
class Circle:
def __init__(self, radius):
self.radius = radius
# class for area calculation
class Area(Circle):
def __init__(self, radius):
super().__init__(radius)
def circle_area(self):
try:
print(3.14 * self.radius * self.radius)
except Check:
print("\n exception occurred")
# class for perimeter calculation
class Perimeter(Circle):
def __init__(self, radius):
super().__init__(radius)
def circle_perimeter(self):
try:
print(2 * 3.14 * self.radius)
except Check:
print("\n exception occurred")
# inheriting exception class
class Check(Exception):
pass
class Rectangle:
def __init__(self, length, breadth):
self.length = length
self.breadth = breadth
# class for area calculation
class Area(Rectangle):
def __init__(self, length, breadth):
super().__init__(length, breadth)
def rectangle_area(self):
try:
print(self.length * self.breadth)
except Check:
print("\n exception occurred")
# class for perimeter calculation
class Perimeter(Rectangle):
def __init__(self, length, breadth):
super().__init__(length, breadth)
def rectangle_perimeter(self):
try:
print(2 * (self.length + self.breadth))
except Check:
print("\n exception occurred")
# inheriting exception class
class Check(Exception):
pass
class Square:
def __init__(self, side_length):
self.length = side_length
# class for area calculation
class Area(Square):
def __init__(self, length):
super().__init__(length)
def square_area(self):
try:
print(self.length * self.length)
except Check:
print("\n exception occurred")
# class for perimeter calculation
class Perimeter(Square):
def __init__(self, length):
super().__init__(length)
def square_perimeter(self):
try:
print(self.length * 4)
except Check:
print("\n exception occurred")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment