I have been told that this code for finding a prime number is wrong. Could anyone explain why? It works for at least the first 100 numbers.
if x<2:
return 'It is neither prime nor composite'
elif x==2 or x==3:
return 'It is a prime number'
else:
for i in range(2,int(x**0.5)+1):
print(i)
if x%i==0 :
return 'It is not a prime number'
break
else:
return 'It is a prime number'
3
, int(n ** 0.5)+1, 2): Why not starting with 3 in the range? Because it will save a lot of computations... – Daniel Hao