-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.4.py
37 lines (34 loc) · 833 Bytes
/
7.4.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
class fraction:
def __init__(self,ss=0,mm=1):
self.s=ss
self.m=mm
def mul(self,other):
result=fraction()
result.s=self.s*other.s
result.m=self.m*other.m
return result
def sum(self,other):
result=fraction()
result.s=self.s*other.m+other.s*self.m
result.m=self.m*other.m
return result
def sub(self):
result=fraction()
result.s=self.s*other.m-other.s*self.m
result.m=self.m*other.m
return result
def dev(self):
result=fraction()
result.s=self.s*other.m
result.m=self.m*other.s
return result
def show(self):
print(self.s,'/',self.m)
a=fraction(2,3)
a.show()
b=fraction(4,5)
b.show()
c=a.sum(b)
c.show()
d=b.mul(a)
d.show()