python - Return The Lowest Factor -
i'm kind of struggling on homework question
define method below return lowest factor of arbitrary integer. lowest factor smallest number greater 1 divide evenly parameter (which 2 or higher)
this far i've gotten.
def first_factor(n): num in range(1,n): if n % num == 0: return n
so return prime numbers how return lowest number? thank you
return num
instead of n
iterate until sqrt(n)
(inclusive), if there no factors smaller or equal sqrt(n)
number prime.
Comments
Post a Comment