Some key concepts
import
its containint module.
In [ ]:
5 / 3
In [ ]:
5 % 3
In [ ]:
import numpy as np
value = 4
is_prime = True
upper = int(np.ceil(np.sqrt(value)))
for divisor in range(2, upper+1):
if value % divisor == 0:
is_prime = False
break
print(is_prime)
In [ ]:
value = 4
def isPrime(value):
is_prime = True
upper = int(np.ceil(np.sqrt(value)))
if value == 2: # THIS IS TERRIBLE
return is_prime
for divisor in range(2, upper+1):
if value % divisor == 0:
is_prime = False
break
return is_prime
In [ ]:
for val in range(2, 20):
print("%d: %d" % (val, isPrime(val)))
In [2]:
import is_prime
is_prime.isPrime(4)
Out[2]:
In [4]:
for val in range(2, 20):
print("%d: %d" % (val, is_prime.isPrime(val)))
Exercise: Put this new function into a different python module and call it from the notebook.