Commit 97245889 by arjun.b

Assignment 1

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$" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ 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" 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/Assignment-1.iml" filepath="$PROJECT_DIR$/.idea/Assignment-1.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 shape.rectangle import Rect
from shape.Circle import Circle
from shape.square import Square
i = 1
while i == 1:
print("enter the choice \n1.area and perimeter of rectangle\n"
"2.area and perimeter of circle\n"
"3.area and perimeter of square\n"
"4.exit")
choice = int(input("enter your choice"))
if choice == 1:
length = float(input("enter the length of the rectangle"))
width = float(input("enter the width of the rectangle"))
obj_rect = Rect(length, width) # create the object of the class Rect
print("area of rectangle=", obj_rect.area())
print("perimeter of rectangle=", obj_rect.perimetr())
elif choice == 2:
# initializing the radius of the circle
radius = float(input("enter the radius"))
obj_cir = Circle(radius) # create the object of the class Circle
print("area of circle=", obj_cir.area(), "\n", "perimeter of circle", obj_cir.perimetr())
# initializing the side of the square
elif choice == 3:
side = float(input("enter the side of the square"))
obj_sqr = Square(side) # create the object of the class Square
print("area of Square=", obj_sqr.area(), "\n", "perimeter of square", obj_sqr.perimtr())
elif choice == 4:
i = 0
class myException(Exception):
pass
class Circle:
def __init__(self, radius):
self.radius = radius
def area(self):
try:
return 3.14 * self.radius * self.radius
except myException:
print("exception occurred")
def perimetr(self):
try:
return 2 * 3.14 * self.radius
except myException:
print("exception occurred")
#exception
class MyException(Exception):
pass
class Rect:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
try:
return self.length * self.width
except MyException:
print("exception occurred")
def perimetr(self):
try:
c = self.length * 2 + self.width * 2
return c
except MyException:
print("exception occurred")
class myException(Exception):
pass
class Square:
def __init__(self, side):
self.side = side
def area(self):
try:
return self.side * self.side
except myException:
print("exception occurred")
def perimtr(self):
try:
return 4 * self.side
except myException:
print("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