Commit 04f6ef38 authored by arun.uday's avatar arun.uday

migrate to gitlab-pm

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
from scripts.services.main_service import shapes
# calling services
print("This program is to find the area and perimeter of shapes.....")
shapes()
# value of pi
pi = 3.14
# import pi from constant
from scripts.constants import values
# 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 values.pi * 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 * values.pi * 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}')
# handler packages for shapes
from scripts.core.handlers import Rectangle, Circle, Square
# return statement for invalid choice
def get_rectangle(calculation_choice):
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()}')
return 0
elif calculation_choice == 'perimeter':
print(f'Perimeter : {Rectangle.Perimeter(rect_length, rect_breadth).display_perimeter()}')
return 0
else:
return 1
def get_circle(calculation_choice):
circle_radius = int(input("Enter the radius"))
if calculation_choice == 'area':
print(f'Area : {Circle.Area(circle_radius).display_area()}')
return 0
elif calculation_choice == 'perimeter':
print(f'Perimeter : {Circle.Perimeter(circle_radius).display_perimeter()}')
return 0
else:
return 1
def get_square(calculation_choice):
square_side = int(input("Enter the side"))
if calculation_choice == 'area':
print(f'Area : {Square.Area(square_side).display_area()}')
return 0
elif calculation_choice == 'perimeter':
print(f'Perimeter : {Square.Perimeter(square_side).display_perimeter()}')
return 0
else:
return 1
# Importing choice selection module
from scripts.services.choice_selection import get_rectangle, get_circle, get_square
# core code
def shapes():
while True:
# checks for calculation choice error
error = 0
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':
error = get_rectangle(calculation_choice)
# choice is circle
elif shape_choice == 'circle':
error = get_circle(calculation_choice)
# choice is square
elif shape_choice == 'square':
error = get_square(calculation_choice)
# invalid choice
else:
print("Please check the spelling.....")
# invalid calculation choice
if error == 1:
print("Calculation choice error....")
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