Created
November 22, 2015 19:27
-
-
Save ozgurkaracam/de163319087fac051520 to your computer and use it in GitHub Desktop.
Fraction sınıfının tüm methodlarının gerçeklenmesi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Kesir: | |
| def __init__(self,a,b): | |
| self.pay=a | |
| self.payda=b | |
| def __str__(self): | |
| return str(self.pay)+"/"+str(self.payda) | |
| def __add__(self,o): | |
| tpay=(self.pay*o.payda)+(self.payda*o.pay) | |
| tpayda=self.payda*o.payda | |
| return (Kesir(tpay,tpayda).sadelestir()) | |
| def __mul__(self,o): | |
| cpay=self.pay*o.pay | |
| cpayda=self.payda*o.payda | |
| return Kesir(cpay,cpayda).sadelestir() | |
| def __sub__(self,o): | |
| pay=(self.pay*o.payda)-(self.payda*o.pay) | |
| payda=self.payda*o.payda | |
| return Kesir(pay,payda).sadelestir() | |
| def obeb(a,b): | |
| ebob=0 | |
| i=1 | |
| while i<=a and i<=b: | |
| if a%i==0 and b%i==0: | |
| ebob=i | |
| i=i+1 | |
| return ebob | |
| def sadelestir(self): | |
| ebob=Kesir.obeb(self.pay,self.payda) | |
| a=self.pay/ebob | |
| b=self.payda/ebob | |
| return Kesir(int(a),int(b)) | |
| def ekok(self): | |
| a=self.pay | |
| b=self.payda | |
| okek=(a*b)/Kesir.obeb(a,b) | |
| return int(okek) | |
| def __eq__(self,o): | |
| kesir1=self.pay/self.payda | |
| kesir2=o.pay/o.payda | |
| if kesir1==kesir2: | |
| return True | |
| else: | |
| return False | |
| def __lt__(self,o): | |
| kesir1=self.pay/self.payda | |
| kesir2=o.pay/o.payda | |
| if kesir1<kesir2: | |
| return True | |
| else: | |
| return False | |
| def tambolu(self): | |
| tam=int(self.pay/self.payda) | |
| pay=self.pay%self.payda | |
| payda=self.payda | |
| return str(tam)+" tam "+str(pay)+" bölü "+str(payda) | |
| def __gt__(self,o): | |
| kesir1=self.pay/self.payda | |
| kesir2=o.pay/o.payda | |
| if kesir1>kesir2: | |
| return True | |
| else: | |
| return False | |
| f1=Kesir(1,3) | |
| f2=Kesir(3,6) | |
| f3=f1*f2 | |
| f4=Kesir(6,4) | |
| print(f1+f2) | |
| print (f4.tambolu()) | |
| print (f1*f4) | |
| print (f1==f2) | |
| print (f1<f2) | |
| print (f4>f2) | |
| print (f4.ekok()) #pay ve paydanın ekok u | |
| print (f2-f1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment