'This should be done by checking the remainder obtained when dividing the number n by 2 and then by all odd numbers between 3 and n/2; the number will be prime if and only if all of the remainders are non-zero.'
My problems are that, the code seems to work partially, I test with numbers 13, 131, 20, 21, which are all returned correctly, however if I enter 35 (which isnt prime) the code returns as not prime.
I also get this error if I enter the value 3 (although I believe this is because of the method we have been told to use the number is too small).
Here is my code:
num = int(input("Enter number: ")) if num%2 != 0 : for i in range(3, num/2, 2) : if num%i != 0 : prime = True break else : prime = False break else : prime = False if prime : print('Prime') else : print('Not Prime')
Any help would be much appreciated!
Made a typo, 35 is returned as prime, my mistake.