File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change 1
1
A number is said to be prime if its only factors are 1 and the number itself. The code is an optimized approach to find the number is prime or not.
2
2
``` python
3
- def IsPrime (number ):
3
+ def isPrime (number ):
4
4
if number <= 1 : # Flags if number is less than or equal to 1
5
- print (" False" )
6
- return
5
+ return False
7
6
if number <= 3 : # 2 and 3 are prime numbers
8
- print (" True" )
9
- return
7
+ return True
10
8
if ((number % 2 == 0 ) or (number % 3 == 0 )): # checks for multiples of 2 and 3
11
- print (" False" )
12
- return
9
+ return False
13
10
i = 5
14
11
while (i * i <= number):
15
12
if (number % i == 0 or number % (i + 2 ) == 0 ):
16
- print (" False" )
17
- return
13
+ return False
18
14
i = i + 6
19
- print (" True" )
20
- return
15
+ return True
21
16
22
17
23
18
24
- ```
19
+ ```
You can’t perform that action at this time.
0 commit comments