Chapter 8 correction for problem 3
This commit is contained in:
parent
d7f61e852c
commit
82c9a03dae
1 changed files with 7 additions and 18 deletions
|
|
@ -2,23 +2,12 @@
|
||||||
# Chapter 8
|
# Chapter 8
|
||||||
# Problem 3
|
# Problem 3
|
||||||
|
|
||||||
import math
|
|
||||||
|
|
||||||
def is_prime(n):
|
def is_prime(n):
|
||||||
# your code here
|
# your code
|
||||||
|
|
||||||
x = 3
|
for i in range (2, n):
|
||||||
|
if n % i == 0:
|
||||||
if abs(n) > 2:
|
return False
|
||||||
while x < math.sqrt(n):
|
return True
|
||||||
if n % 2 == 0:
|
|
||||||
return False
|
|
||||||
elif n % x == 0:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
x += 2
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
print(is_prime(4813))
|
print(is_prime(25))
|
||||||
Loading…
Reference in a new issue