-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp56.py
More file actions
43 lines (33 loc) · 789 Bytes
/
exp56.py
File metadata and controls
43 lines (33 loc) · 789 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
31
32
33
34
35
36
37
38
39
40
41
42
43
#operator overloading #56/63
class student:
def __init__(self, m1, m2):
self.m1=m1
self.m2=m2
def __add__(self, other):
m1= self.m1 + other.m1
m2= self.m2 + other.m2
s3=student(m1,m2)
return s3
def __gt__(self, other):
r1= self.m1 + self.m2
r2= self.m1 + self.m2
if r1 > r2:
return True
else:
return False
def __str__(self):
return "{} {}".format(self.m1, self.m2)
#return self.m1, self.m2
s1=student(45,67)
s2=student(60,55)
s3=s1+s2 #->student.__add__(s1,s2)
print(s3.m1)
print(s3.m2)
if s1 > s2:
print('s1 wins')
else:
print('s2 wins')
a=9
print(a.__str__())
print(s1.__str__())
print(s2)