File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change 1
- # prime number calculator
1
+ # prime number calculator: find all primes up to n
2
2
3
3
max = int (input ("Find primes up to what number? : " ))
4
4
primeList = []
18
18
primeList .append (x )
19
19
20
20
print (primeList )
21
-
21
+
22
+
23
+ #-------------------------------------------------------------
24
+ # prime number calculator: find the first n primes
25
+
26
+ count = int (input ("Find how many primes?: " ))
27
+ primeList = []
28
+ x = 2
29
+
30
+ while len (primeList ) < count :
31
+ isPrime = True
32
+ index = 0
33
+ root = int (x ** 0.5 ) + 1
34
+
35
+ while index < len (primeList ) and primeList [index ] <= root :
36
+ if x % primeList [index ] == 0 :
37
+ isPrime = False
38
+ break
39
+ index += 1
40
+
41
+ if isPrime :
42
+ primeList .append (x )
43
+
44
+ x += 1
45
+
46
+ print (primeList )
You can’t perform that action at this time.
0 commit comments