scientific-programming-exer.../ex_19.py
2018-11-21 16:30:46 +01:00

45 lines
965 B
Python

class ext_int(int):
def __new__(cls, *args, **kwargs):
return int.__new__(cls, *args, **kwargs)
def is_prime(self):
if(abs(self) in (1, 0)):
return False
for i in range(2, abs(self)//2 + 1):
if(not self % i):
return False
return True
def is_positive(self):
return self > 0
def is_even(self):
return not self % 2
def is_odd(self):
return not self.is_even()
def get_inverse(self):
return 1 / self
class shitty_list(list):
def __new__(cls, *args, **kwargs):
return list.__new__(cls, *args, **kwargs)
def divide(self):
return (self[:len(self)//2], self[len(self)//2:])
if( __name__ == "__main__"):
print(ext_int(3).is_prime())
print(ext_int(4).is_prime())
print(ext_int(2).is_positive())
print(ext_int(-2).is_positive())
print(ext_int(2).is_even())
print(ext_int(3).is_even())
print(ext_int(2).is_odd())
print(ext_int(3).is_odd())
print(ext_int(2).get_inverse())
print()
print(shitty_list("abcdefg").divide())