Commit 7e5ccd97 by ajil.k

updated with new project structure.

parent 4dff9579
from scripts.services.main import shape
shape()
\ No newline at end of file
from scripts.constants.values import PI
# inherited Exception class # inherited Exception class
class TestException(Exception): class TestException(Exception):
pass pass
...@@ -9,7 +10,7 @@ class Circle: ...@@ -9,7 +10,7 @@ class Circle:
def area_circle(self): def area_circle(self):
try: try:
area = 3.14 * self.radius * self.radius area = PI * self.radius * self.radius
return area return area
except TestException: except TestException:
print("\nException Occurred\n") print("\nException Occurred\n")
...@@ -18,7 +19,7 @@ class Circle: ...@@ -18,7 +19,7 @@ class Circle:
def perimeter_circle(self): def perimeter_circle(self):
try: try:
perimeter = 2 * 3.14 * self.radius perimeter = 2 * PI * self.radius
return perimeter return perimeter
except TestException: except TestException:
print("\nException Occurred\n") print("\nException Occurred\n")
......
"""import shapes from package 'shape'.""" """import shapes from package 'shape'."""
from shape.rectangle import Rect from scripts.core.handlers.rectangle import Rect
from shape.square import Square from scripts.core.handlers.square import Square
from shape.circle import Circle from scripts.core.handlers.circle import Circle
# iterating variable def shape():
i = 1 # iterating variable
while i == 1: i = 1
print("----------Area & Perimeter----------\n" while i == 1:
"1.Rectangle\n" print("----------Area & Perimeter----------\n"
"2.Circle\n" "1.Rectangle\n"
"3.Square\n" "2.Circle\n"
"4.Enter 0 to exit\n") "3.Square\n"
choice = int(input("Enter the choice: ")) "4.Exit\n")
if choice == 1: choice = int(input("Enter the choice: "))
rect_length = float(input( if choice == 1:
"Enter the length: ")) rect_length = float(input(
rect_breadth = float(input( "Enter the length: "))
"Enter the breadth: ")) rect_breadth = float(input(
# creating object of Rect "Enter the breadth: "))
rect_inst = Rect(rect_length, rect_breadth) # creating object of Rect
print("Area of Rectangle: ", rect_inst = Rect(rect_length, rect_breadth)
rect_inst.area_rect()) print("Area of Rectangle: ",
print("Perimeter of Rectangle: ", rect_inst.area_rect())
rect_inst.perimeter_rect()) print("Perimeter of Rectangle: ",
elif choice == 2: rect_inst.perimeter_rect())
circle_radius = float(input( elif choice == 2:
"Enter the radius: ")) circle_radius = float(input(
# creating object of Circle "Enter the radius: "))
circle_inst = Circle(circle_radius) # creating object of Circle
print("Area of Circle: ", circle_inst = Circle(circle_radius)
circle_inst.area_circle()) print("Area of Circle: ",
print("\nCircumference of Circle: ", circle_inst.area_circle())
circle_inst.perimeter_circle()) print("\nCircumference of Circle: ",
elif choice == 3: circle_inst.perimeter_circle())
square_side = float(input( elif choice == 3:
"Enter the side length: ")) square_side = float(input(
# creating object of Square "Enter the side length: "))
square_inst = Square(square_side) # creating object of Square
print("Area of Square: ", square_inst = Square(square_side)
square_inst.area_square()) print("Area of Square: ",
print("Perimeter of Square: ", square_inst.area_square())
square_inst.perimeter_square()) print("Perimeter of Square: ",
elif choice == 0: square_inst.perimeter_square())
i = 0 elif choice == 4:
# Exit if ch i = 0
# Exit if choice is 4
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