Commit 2528cc56 by arun.uday

first commit

parents
# Default ignored files
/shelf/
/workspace.xml
<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 (shapes)" 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/shapes.iml" filepath="$PROJECT_DIR$/.idea/shapes.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?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
<?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
# Importing modules rectangle, circle, square from scripts
from scripts import Rectangle
from scripts import Circle
from scripts import Square
# User Inputs
while True:
shape_choice = input("Enter rectangle/ circle/ square/ quit")
if shape_choice == 'quit':
break
calculation_choice = input("Enter area/ perimeter")
# choice is rectangle
if shape_choice == 'rectangle':
rect_length = int(input("Enter the length"))
rect_breadth = int(input("Enter the breadth"))
if calculation_choice == 'area':
print(f'Area : {Rectangle.Area(rect_length, rect_breadth).display_area()}')
elif calculation_choice == 'perimeter':
print(f'Perimeter : {Rectangle.Perimeter(rect_length, rect_breadth).display_perimeter()}')
else:
print("Invalid calculation choice")
# choice is circle
elif shape_choice == 'circle':
circle_radius = int(input("Enter the radius"))
if calculation_choice == 'area':
print(f'Area : {Circle.Area(circle_radius).display_area()}')
elif calculation_choice == 'perimeter':
print(f'Perimeter : {Circle.Perimeter(circle_radius).display_perimeter()}')
else:
print("Invalid calculation choice")
# choice is square
elif shape_choice == 'square':
square_side = int(input("Enter the side"))
if calculation_choice == 'area':
print(f'Area : {Square.Area(square_side).display_area()}')
elif calculation_choice == 'perimeter':
print(f'Perimeter : {Square.Perimeter(square_side).display_perimeter()}')
else:
print("Invalid calculation choice")
# invalid choice
else:
print("Please check the spelling.....")
# class for shape circle
class Circle:
def __init__(self, circle_radius):
self.radius = circle_radius
# area child class inheriting class Circle
class Area(Circle):
def __init__(self, circle_radius):
super().__init__(circle_radius)
def display_area(self):
try:
return 3.14 * self.radius * self.radius
except Exception as e:
print(f'Exception occurred: {e}')
# perimeter child class inheriting class Circle
class Perimeter(Circle):
def __init__(self, circle_radius):
super().__init__(circle_radius)
def display_perimeter(self):
try:
return 2 * 3.14 * self.radius
except Exception as e:
print(f'Exception occurred: {e}')
# class for shape rectangle
class Rectangle:
def __init__(self, rect_length, rect_breadth):
self.length = rect_length
self.breadth = rect_breadth
# area child class inheriting class rectangle
class Area(Rectangle):
def __init__(self, rect_length, rect_breadth):
super().__init__(rect_length, rect_breadth)
def display_area(self):
try:
return self.length * self.breadth
except Exception as e:
print(f'Exception occurred: {e}')
# perimeter child class inheriting class rectangle
class Perimeter(Rectangle):
def __init__(self, rect_length, rect_breadth):
super().__init__(rect_length, rect_breadth)
def display_perimeter(self):
try:
return 2 + (self.length + self.breadth)
except Exception as e:
print(f'Exception occurred: {e}')
# class for shape Square
class Square:
def __init__(self, square_side):
self.side = square_side
# area child class inheriting class Square
class Area(Square):
def __init__(self, square_side):
super().__init__(square_side)
def display_area(self):
try:
return self.side * self.side
except Exception as e:
print(f'Exception occurred: {e}')
# perimeter child class inheriting class Circle
class Perimeter(Square):
def __init__(self, square_side):
super().__init__(square_side)
def display_perimeter(self):
try:
return 4 * self.side
except Exception as e:
print(f'Exception occurred: {e}')
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