Skip to content

Commit 34050d9

Browse files
authored
Improved the Functionality of isPrime Function.
I improved the functionality of the isPrime Function to return Boolean values instead of just printing them so that it can also be used on other cases (i.e. if-else statements and while loops). This also compliments to printing True or False values. Also, I changed the capitalization of the isPrime Function to Camel Case just to cope up with the common convention🙂.
1 parent 4653b1e commit 34050d9

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
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.
22
``` python
3-
def IsPrime(number):
3+
def isPrime(number):
44
if number <= 1: #Flags if number is less than or equal to 1
5-
print("False")
6-
return
5+
return False
76
if number <= 3: #2 and 3 are prime numbers
8-
print("True")
9-
return
7+
return True
108
if ((number % 2 == 0) or (number % 3 == 0)): #checks for multiples of 2 and 3
11-
print("False")
12-
return
9+
return False
1310
i = 5
1411
while (i * i <= number):
1512
if (number % i == 0 or number % (i + 2) == 0):
16-
print("False")
17-
return
13+
return False
1814
i = i + 6
19-
print("True")
20-
return
15+
return True
2116

2217

2318

24-
```
19+
```

0 commit comments

Comments
 (0)