From 82c9a03dae55a73143940d752684a82256f8781a Mon Sep 17 00:00:00 2001 From: lolabird Date: Sun, 15 Oct 2023 18:11:45 -0600 Subject: [PATCH] Chapter 8 correction for problem 3 --- .../Python-files/Problem3.py | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/thinkcspy/Chapter-8-Exercises/Python-files/Problem3.py b/thinkcspy/Chapter-8-Exercises/Python-files/Problem3.py index 959123c..1cc66e5 100644 --- a/thinkcspy/Chapter-8-Exercises/Python-files/Problem3.py +++ b/thinkcspy/Chapter-8-Exercises/Python-files/Problem3.py @@ -2,23 +2,12 @@ # 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 + # your code + + for i in range (2, n): + if n % i == 0: + return False + return True -print(is_prime(4813)) \ No newline at end of file +print(is_prime(25)) \ No newline at end of file