I need to find The smallest positive factor (apart from 1) of the integer ânâ, where n â¥ 2
<p>i can only use for loops and range.. no while loop.</p>

<pre><code>def SmalletFactor(n):
    # find the  smallest  positive  factor (apart from 1) of the 
    # integer ânâ, where n â¥ 2
    result = 0
    m = n
    for i in range(2, n -1):
        if n &gt;=2 and (n % i == 0):
            result = n // i
            if result == 0:
                #im not getting to this step???
                result = m 
                if result % i != 0:
                    result = n // i
    else:
        return(result)
</code></pre>

<p>Your code is more complicated than it needs to be. Consider the following:</p>

<pre><code>def SmallestFactor(n):
    for i in range(2, n + 1): # n + 1 ensures that n itself 
                              # is returned if n is prime
        if n % i == 0:
            return i
    return None # this should never happen for valid input
</code></pre>

<p>You may also want to consider the behaviour of your function if invalid input is given (e.g. a string, a negative number etc.).</p>

python factors