Determine if num
is prime
In [12]:
import numpy as np
# Determine if num is prime
# This code has a bug. What is it?
# Also, the efficiency of the code can be improved. How?
num = 8
upper = int(np.sqrt(num)) + 1:
if num % integer == 0:
print("Not prime!")
is_prime = False
import pdb; pdb.set_trace()
if is_prime:
print("Is prime!")
is_prime = True
for integer in range(2, upper)
In [ ]:
# Extending the code to test if a list of numbers is prime
a_list = [3, 6, 11]
# How do we test all elements of the list?
In [15]:
# Transforming the prime number calculation script into a function
def check_prime(num):
upper = int(np.sqrt(num)) + 1
for integer in range(2, upper):
if num % integer == 0:
return False
return True
In [19]:
check_prime(-3)
Problem: Write a function that finds all of the prime numbers less than a given value.
In [ ]:
# Function header: name, arguments
# Function logic
# return somethin