Commit fad8e324 by mohammed.shibili

altered coding standard

parent f2ebfddb
from scripts.servieces.main import shapes
print("program for finding area and perimeter of shapes")
shapes()
python 3.9.13
\ No newline at end of file
from scripts.constants import constant_values
# inheriting exception class # inheriting exception class
class Check(Exception): class Check(Exception):
pass pass
...@@ -16,7 +19,7 @@ class Area(Circle): ...@@ -16,7 +19,7 @@ class Area(Circle):
def circle_area(self): def circle_area(self):
try: try:
print(3.14 * self.radius * self.radius) print("area=", constant_values.pi * self.radius * self.radius)
except Check: except Check:
print("\n exception occurred") print("\n exception occurred")
...@@ -29,6 +32,6 @@ class Perimeter(Circle): ...@@ -29,6 +32,6 @@ class Perimeter(Circle):
def circle_perimeter(self): def circle_perimeter(self):
try: try:
print(2 * 3.14 * self.radius) print("perimeter=", 2 * constant_values.pi * self.radius)
except Check: except Check:
print("\n exception occurred") print("\n exception occurred")
...@@ -16,7 +16,7 @@ class Area(Rectangle): ...@@ -16,7 +16,7 @@ class Area(Rectangle):
def rectangle_area(self): def rectangle_area(self):
try: try:
print(self.length * self.breadth) print("area", self.length * self.breadth)
except Check: except Check:
print("\n exception occurred") print("\n exception occurred")
...@@ -28,6 +28,6 @@ class Perimeter(Rectangle): ...@@ -28,6 +28,6 @@ class Perimeter(Rectangle):
def rectangle_perimeter(self): def rectangle_perimeter(self):
try: try:
print(2 * (self.length + self.breadth)) print("perimeter=", 2 * (self.length + self.breadth))
except Check: except Check:
print("\n exception occurred") print("\n exception occurred")
...@@ -15,7 +15,7 @@ class Area(Square): ...@@ -15,7 +15,7 @@ class Area(Square):
def square_area(self): def square_area(self):
try: try:
print(self.length * self.length) print("area=", self.length * self.length)
except Check: except Check:
print("\n exception occurred") print("\n exception occurred")
...@@ -27,6 +27,6 @@ class Perimeter(Square): ...@@ -27,6 +27,6 @@ class Perimeter(Square):
def square_perimeter(self): def square_perimeter(self):
try: try:
print(self.length * 4) print("perimeter=", self.length * 4)
except Check: except Check:
print("\n exception occurred") print("\n exception occurred")
from shapes import square # importing modules
from shapes import rectangle from scripts.core.handler import circle, rectangle, square
from shapes import circle
while True:
def shapes():
i = 1
while i == 1:
# selecting shape by user # selecting shape by user
print("1.square \n 2.rectangle \n 3.circle \n") print("1.square \n 2.rectangle \n 3.circle \n 0.Exit")
shape = int(input("enter your choice\n")) shape = int(input("enter your choice\n"))
# Exception raise for wrong choice # calling for calculation of square
if shape > 4 or shape < 0:
raise Exception("invalid choice of shape")
# calling for calculation
if shape == 1: if shape == 1:
side = float(input("enter side length")) side = float(input("enter side length"))
square.Area(side).square_area() square.Area(side).square_area()
square.Perimeter(side).square_perimeter() square.Perimeter(side).square_perimeter()
# calling for calculation of rectangle
elif shape == 2: elif shape == 2:
length = float(input("enter the length")) length = float(input("enter the length"))
breadth = float(input("enter the breadth")) breadth = float(input("enter the breadth"))
rectangle.Area(length, breadth).rectangle_area() rectangle.Area(length, breadth).rectangle_area()
rectangle.Perimeter(length, breadth).rectangle_perimeter() rectangle.Perimeter(length, breadth).rectangle_perimeter()
# calling for calculation of circle
elif shape == 3: elif shape == 3:
radius = float(input("enter the radius")) radius = float(input("enter the radius"))
circle.Area(20).circle_area() circle.Area(radius).circle_area()
circle.Perimeter(20).circle_perimeter() circle.Perimeter(radius).circle_perimeter()
elif shape == 0:
i = 0
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