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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -