We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7a2ca08 commit 23dde35Copy full SHA for 23dde35
Primes.py
@@ -1,4 +1,4 @@
1
-# prime number calculator
+# prime number calculator: find all primes up to n
2
3
max = int(input("Find primes up to what number? : "))
4
primeList = []
@@ -18,4 +18,29 @@
18
primeList.append(x)
19
20
print(primeList)
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)
0 commit comments