else clause into the same indentation as the for loop solve this?
Back in previous exercise we have learned about
Generally we use for/else with conjunction with
But as here we have return so we do not have to worry much. (as break and return both acts as final exit door)
If a number in not prime then for loop keep goes on and at one point it finds that
x % n == 0 evaluates True so it executes the if clause body by returning
but suppose a number is a prime,then it tests for all conditions when it does not find
x % n == 0 evaluated to
True ,it just run else part of for loop by returning
Also you mention removing the else clause entirely and leaving the return True statement. How would that look/work?
Actually this one is obvious even it looks weird.
These two blocks..
if x < 2:
for n in range(2, x):
if x % n == 0:
(there should one conditional statement there for prime number
These two blocks actually checks if a number is not a prime,If our number does not satisfies these criteria of Non-prime number.
It simply means that our number is a prime so we should return
True,we can simply add a return statement returning
True at the last.
I hope it helps.