-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime_nums.py
More file actions
42 lines (34 loc) · 1.23 KB
/
prime_nums.py
File metadata and controls
42 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Program will have to prime numbers
#
# What is a prime number?
# It is a whole number greater than one.
# Prime numbers are divisible only by the number 1 or itself.
# E.g.: 2, 3, 5, 7 and 11
#
#
# Figuring out the prime numbers:
# -------------------------------------------
# To prove whether a number is a prime number,
# first try dividing it by 2,
# and see if you get a whole number.
# If you do, it can't be a prime number.
# If you don't get a whole number, next try dividing
# it by prime numbers: 3, 5, 7, 11 (9 is divisible by 3) and so on,
# always dividing by a prime number
# -------------------------------------------
#
#
class Prime:
def __init__(self, limit: int):
self.limit: int = limit # limits the max prime number generated
self.numbersToLimit = [] # list of all whole numbers up to limit
for i in range(self.limit): # filling list with numbers using for loop
self.numbersToLimit.append(i+1)
self.prime_numbers = [] # list for all the prime numbers
def getAllPrimeNumbers(self):
for num in self.numbersToLimit:
if((num != 1) and (not num % 2 == 0)): # see instructions at the top
self.prime_numbers.append(num)
return self.prime_numbers
t = Prime(12)
print(t.getAllPrimeNumbers())