forked from Ranabetuluzun/Python_Modul_Week_5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ1.py
More file actions
27 lines (20 loc) · 917 Bytes
/
Q1.py
File metadata and controls
27 lines (20 loc) · 917 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
# Create a Python class called "Rectangle" that represents a rectangle. The Rectangle class must have the following properties and methods:
# ##### Features:
# - width (an integer)
# - height (an integer)
# ##### Methods:
# - area(self): A method that calculates and returns the area of the rectangle.
# - perimeter(self): A method that calculates and returns the perimeter of the rectangle.
# - Create an instance of Rectangle class, set its width to 5 and height to 7, then print its area and perimeter.
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def area(self):
return self.width * self.height
def perimeter(self):
return 2 * (self.width + self.height)
#create an object of Rectangle
my_rectangle = Rectangle(5, 7)
print("Area:", my_rectangle.area())
print("Perimeter:", my_rectangle.perimeter())