Repository navigation
Expand file tree
/
Copy pathnumber.py
More file actions
105 lines (86 loc) · 2.4 KB
/
Copy pathnumber.py
File metadata and controls
105 lines (86 loc) · 2.4 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import math
class Number:
def __init__(self,num):
self.number = num
def data_type(self):
'''
this method returns the type of the number.
'''
return type(self.number)
def len(self) -> int:
'''
this method returns the length of the number.
Args:
No
Returns:
int: the length of the number.
'''
return len(str(self.number))
def is_positive(self) -> bool:
'''
this mehtod returns true if number is positive otherwise false.
Args:
No
Returns:
bool: true if number is positive otherwise false.
'''
return self.number > 0
def is_negative(self) -> bool:
'''
this mehtod returns true if number is negative otherwise false.
Args:
No
Returns:
bool: true if number is negative otherwise false.
'''
return self.number < 0
def is_zero(self) -> bool:
'''
this mehtod returns true if number is zero otherwise false.
Args:
No
Returns:
bool: true if number is zero otherwise false.
'''
return self.number == 0
def is_even(self) -> bool:
'''
this mehtod returns true if number is even number otherwise false.
Args:
No
Returns:
bool: true if number is even number otherwise false.
'''
return self.number % 2 == 0
def is_odd(self) -> bool:
'''
this mehtod returns true if number is odd number otherwise false.
Args:
No
Returns:
bool: true if number is odd number otherwise false.
'''
return self.number % 2 == 1
def is_prime(self) -> bool:
'''
this mehtod returns true if number is prime otherwise false.
Args:
No
Returns:
bool: true if number is prime otherwise false.
'''
if self.number == 2:
return True
for i in range(2, int(math.sqrt(self.number)) +1):
if i % i == 0:
return False
return True
def int_to_str(self) -> str:
'''
this method converts to string.
Args:
No
Returns:
str: convert to string
'''
return str(self.number)