Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Rat:
- def __init__(self,a=0,b=1):
- if(b!=0):
- self.num=a
- self.den=b
- else:
- self.num=a
- self.den=1
- def __str__(self):
- return str(self.num)+"/"+str(self.den)
- def check(self):
- if den==0: return False
- return True
- def reduce(self):
- n=self.num
- m=self.den
- if n > m:
- k = n
- else:
- k = m
- while k != 1:
- if n % k == 0 and m % k == 0:
- return n // k, m // k
- else:
- k -= 1
- return Rat(n,m)
- if __name__=="__main__":
- t=Rat(25,5)
- print(t.reduce())
Advertisement
Add Comment
Please, Sign In to add comment