Add Chapter 8 python files
This commit is contained in:
parent
2424fa6028
commit
5c38f5ef86
6 changed files with 228 additions and 0 deletions
24
thinkcspy/Chapter-8-Exercises/Python-files/Problem3.py
Normal file
24
thinkcspy/Chapter-8-Exercises/Python-files/Problem3.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Runestone.Academy thinkcspy course
|
||||
# Chapter 8
|
||||
# Problem 3
|
||||
|
||||
import math
|
||||
|
||||
def is_prime(n):
|
||||
# your code here
|
||||
|
||||
x = 3
|
||||
|
||||
if abs(n) > 2:
|
||||
while x < math.sqrt(n):
|
||||
if n % 2 == 0:
|
||||
return False
|
||||
elif n % x == 0:
|
||||
return False
|
||||
else:
|
||||
x += 2
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
print(is_prime(4813))
|
||||
Loading…
Reference in a new issue