-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_rectangle.py
97 lines (91 loc) · 2.36 KB
/
class_rectangle.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'''class rectangle:
def setdata(self):
self.length = int(input('Enter any length value'))
self.breadth = int(input('Enter any breadth value'))
def putdata(self):
print('The lenght is ',self.length)
print('The breadth is ',self.breadth)
def area(self):
a = self.length*self.breadth
return print('Area is =',a)
def perimeter(self):
p = 2*(self.length+self.breadth)
return print('Perimeter is = ',p)
def setlength(self):
ca = input("Do you want to change lenght choose y/n ")
if ca == 'y':
self.length = int(input("Enter new length value"))
r = rectangle()
r.setdata()
r.putdata()
r.area()
r.perimeter()
r.setlength()
r.putdata()
'''
'''# constructor
class rectangle:
def __init__(self,l,b):
self.length = l
self.breadth = b
def putdata(self):
print('The length is ',self.length)
print('The breadth is ',self.breadth)
def setlenbread(self):
self.length = int(input('Enter new length'))
self.breadth = int(input('Enter new breadth'))
def area(self):
self.area = self.length * self.breadth
print('The area of rectangle is :',self.area)
r1 = rectangle(10,20)
r1.putdata()
r2 = rectangle(40,50)
r2.putdata()
r1.setlenbread()
r2.setlenbread()
r1.area()
r2.area()
'''
'''# destructur
class rectangle:
count = 0
def __init__(self,l,b):
self.length = l
self.breadth = b
rectangle.count +=1
def __del__(self):
print(f'one object is deleted')
rectangle.count -= 1
def display(self):
print(self.length)
print(self.breadth)
def __str__(self):
return 'length :' + str(self.length)+ ' '+ 'breadth:' + str(self.breadth)
r1 = rectangle(10,20)
r2 = rectangle(40,6)
r1.display()
print(rectangle.count)
del r1
print(rectangle.count)
print(r2)
#print(r1)'''
'''
class rectangle:
count = 0
def __init__(self,l,b):
self.__length = l
self.breadth = b
rectangle.count +=1
def __del__(self):
print(f'one object is deleted')
rectangle.count -= 1
def area(self):
self.area = self.__length * self.breadth
print(self.area)
def __str__(self):
return 'length :' + str(self.length)+ ' '+ 'breadth:' + str(self.breadth)
r1 = rectangle(12,6)
print(r1.breadth)
r1.area()
print(__length)
'''