forked from fenyx-it-academy/Class7-Python-Module-Week4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasgn2.py
More file actions
30 lines (23 loc) · 957 Bytes
/
asgn2.py
File metadata and controls
30 lines (23 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 1. Write a `Rectangle` class, allowing you to build a rectangle with `length`
# and `width` attributes.
# 2. Create a `perimeter()` method to calculate the perimeter
# of the rectangle and an `area()` method to calculate the area of the rectangle.
# 3. Create a method `display()` that displays the length, width, perimeter and area of an
# object created using an instantiation on `Rectangle` class.
from operator import length_hint
class rectangle():
def __init__(self,width,lenght):
self.width=width
self.lenght=lenght
def perimeter(self):
perimeter=(self.lenght +self.width)*2
return perimeter
def area(self):
area=self.lenght*self.width
return area
def display(self):
x=rectangle.area()
y=rectangle.perimeter()
return f'lenght:{self.lenght}, width:{self.width},area:{x},perimeter:{y}'
rectangle=rectangle(3,4)
print(rectangle.display())