-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime_no_function.py
More file actions
32 lines (29 loc) · 872 Bytes
/
prime_no_function.py
File metadata and controls
32 lines (29 loc) · 872 Bytes
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
def number(num):
if type(num) is not int:
return "invalid format"
else:
return num
def prime(n):
if_prime = True
# since 2, 0 or negative numbers are not prime numbers, we use it
x = 2
if n == 0 or n < 0:
return False
else:
for i in range(2,n):
#checks if the remainder of number(n) divided current iteration value gives zero
if n % i == 0:
# in a case result is Zero(0), means n is divisible by another value apart from itsself and 1
if_prime = False
# the value status returns tells if number is prime=True or not=False
return if_prime
def array_of_prime_integers(n):
# has an array/list of prime numbers
array_of_prime_numbers = []
for i in n:
if prime(i):
# if True append to list
array_of_prime_numbers.append(i)
else:
return False
return array_of_prime_numbers