mirror of
https://github.com/Sosokker/Calculator-for-Matrix-and-Algebra.git
synced 2025-12-19 21:24:05 +01:00
Checking Minus sign and Check devide by 0 error
This commit is contained in:
parent
314e374c60
commit
b2fe8a53f4
BIN
nessesary/__pycache__/fraction.cpython-310.pyc
Normal file
BIN
nessesary/__pycache__/fraction.cpython-310.pyc
Normal file
Binary file not shown.
@ -1,9 +1,38 @@
|
|||||||
class Fraction:
|
class Fraction:
|
||||||
def __init__(self, numer, denom):
|
def __init__(self, numer, denom):
|
||||||
self.numer = numer
|
if numer < 0 and denom < 0:
|
||||||
self.denom = denom
|
numer = -numer
|
||||||
|
denom = -denom
|
||||||
|
if denom < 0:
|
||||||
|
numer = -numer
|
||||||
|
denom = -denom
|
||||||
|
if denom == 0:
|
||||||
|
raise ValueError("Denominator shouldn't be zero.")
|
||||||
|
self.__numer = numer
|
||||||
|
self.__denom = denom
|
||||||
self.floating = numer/denom
|
self.floating = numer/denom
|
||||||
|
|
||||||
|
@property
|
||||||
|
def numer(self):
|
||||||
|
return self.__numer
|
||||||
|
|
||||||
|
@property
|
||||||
|
def denom(self):
|
||||||
|
return self.__denom
|
||||||
|
|
||||||
|
@numer.setter
|
||||||
|
def numer(self, value):
|
||||||
|
self.__numer = value
|
||||||
|
|
||||||
|
@denom.setter
|
||||||
|
def denom(self, value):
|
||||||
|
if denom < 0:
|
||||||
|
numer = -numer
|
||||||
|
denom = -denom
|
||||||
|
if denom == 0:
|
||||||
|
raise ValueError("Denominator shouldn't be zero.")
|
||||||
|
self.__denom = value
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
"""
|
"""
|
||||||
Add Fraction.
|
Add Fraction.
|
||||||
@ -62,4 +91,19 @@ class Fraction:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
|
"""
|
||||||
|
Print Fraction Form.
|
||||||
|
>>> m1 = Fraction(1, 2)
|
||||||
|
>>> print(m1)
|
||||||
|
1/2
|
||||||
|
>>> m2 = Fraction(5, -2)
|
||||||
|
>>> print(m2)
|
||||||
|
-5/2
|
||||||
|
>>> m3 = Fraction(-5, 2)
|
||||||
|
>>> print(m3)
|
||||||
|
-5/2
|
||||||
|
>>> m4 = Fraction(-5, -2)
|
||||||
|
>>> print(m4)
|
||||||
|
5/2
|
||||||
|
"""
|
||||||
return f"{self.numer}/{self.denom}"
|
return f"{self.numer}/{self.denom}"
|
||||||
Loading…
Reference in New Issue
Block a user