Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
training
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
arjun.b
training
Commits
ea54cc90
Commit
ea54cc90
authored
Jan 17, 2023
by
arjun.b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assignment 1
parent
40e5dddd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
10 deletions
+37
-10
index.py
+8
-9
shape/Circle.py
+8
-0
shape/rectangle.py
+14
-1
shape/square.py
+7
-0
No files found.
index.py
View file @
ea54cc90
# importing the modules
from
shape.rectangle
import
Rect
from
shape.rectangle
import
Rect
from
shape.Circle
import
Circle
from
shape.Circle
import
Circle
from
shape.square
import
Square
from
shape.square
import
Square
# collecting the length and width of the rectangle
length
=
float
(
input
(
"enter the length of the rectangle"
))
length
=
float
(
input
(
"enter the length of the rectangle"
))
width
=
float
(
input
(
"enter the width of the rectangle"
))
width
=
float
(
input
(
"enter the width of the rectangle"
))
obj_rect
=
Rect
(
length
,
width
)
# create the object of the class Rect
obj_rect
=
Rect
(
length
,
width
)
# create the object of the class Rect
print
(
"area
="
,
obj_rect
.
area
())
print
(
"area
of rectangle="
,
obj_rect
.
area
())
print
(
"perimeter
="
,
obj_rect
.
perimtr
()
)
print
(
"perimeter
of rectangle="
,
obj_rect
.
perimetr
)
# initializing the radius of the circle
radius
=
float
(
input
(
"enter the radius"
))
radius
=
float
(
input
(
"enter the radius"
))
obj_cir
=
Circle
(
radius
)
# create the object of the class Circle
obj_cir
=
Circle
(
radius
)
# create the object of the class Circle
print
(
"area
="
,
obj_cir
.
area
(),
"
\n
"
,
"perimeter
"
,
obj_cir
.
perimetr
())
print
(
"area
of circle="
,
obj_cir
.
area
(),
"
\n
"
,
"perimeter of circle
"
,
obj_cir
.
perimetr
())
# initializing the side of the square
side
=
float
(
input
(
"enter the side of the square"
))
side
=
float
(
input
(
"enter the side of the square"
))
obj_sqr
=
Square
(
side
)
obj_sqr
=
Square
(
side
)
# create the object of the class Square
print
(
"area
="
,
obj_sqr
.
area
(),
"
\n
"
,
"perimeter
"
,
obj_sqr
.
perimtr
())
print
(
"area
of square="
,
obj_sqr
.
area
(),
"
\n
"
,
"perimeter of square
"
,
obj_sqr
.
perimtr
())
shape/Circle.py
View file @
ea54cc90
class
myException
(
Exception
):
pass
class
Circle
:
class
Circle
:
def
__init__
(
self
,
radius
):
def
__init__
(
self
,
radius
):
self
.
radius
=
radius
self
.
radius
=
radius
def
area
(
self
):
def
area
(
self
):
try
:
return
3.14
*
self
.
radius
*
self
.
radius
return
3.14
*
self
.
radius
*
self
.
radius
except
myException
:
print
(
"exception occurred"
)
def
perimetr
(
self
):
def
perimetr
(
self
):
try
:
return
2
*
3.14
*
self
.
radius
return
2
*
3.14
*
self
.
radius
except
myException
:
print
(
"exception occurred"
)
shape/rectangle.py
View file @
ea54cc90
class
myException
(
Exception
):
pass
class
Rect
:
class
Rect
:
def
__init__
(
self
,
length
,
width
):
def
__init__
(
self
,
length
,
width
):
self
.
length
=
length
self
.
length
=
length
self
.
width
=
width
self
.
width
=
width
def
area
(
self
):
def
area
(
self
):
try
:
return
self
.
length
*
self
.
width
return
self
.
length
*
self
.
width
except
myException
:
print
(
"exception occurred"
)
def
perimtr
(
self
):
def
perimetr
(
self
):
try
:
return
2
*
(
self
.
length
+
self
.
width
)
return
2
*
(
self
.
length
+
self
.
width
)
except
myException
:
print
(
"exception occurred"
)
finally
:
print
(
"-----------"
)
\ No newline at end of file
shape/square.py
View file @
ea54cc90
class
myException
(
Exception
):
pass
class
Square
:
class
Square
:
def
__init__
(
self
,
side
):
def
__init__
(
self
,
side
):
self
.
side
=
side
self
.
side
=
side
...
@@ -5,6 +7,11 @@ class Square:
...
@@ -5,6 +7,11 @@ class Square:
def
area
(
self
):
def
area
(
self
):
try
:
try
:
return
self
.
side
*
self
.
side
return
self
.
side
*
self
.
side
except
myException
:
print
(
"exception occurred"
)
def
perimtr
(
self
):
def
perimtr
(
self
):
try
:
return
4
*
self
.
side
return
4
*
self
.
side
except
myException
:
print
(
"exception occurred"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment