Python 2, 46 65 5252 51 bytes
- Went up to 65 bytes - Fix made thanks to feersum & Mauris
- Went down to 52 bytes - Suggestions made by kirbyfan64sos and accepts in input from STDIN to complete the code.
- Went down to 51 bytes - Suggestion made by
kirbyfan64sos(thanks again!) to remove the space between1andand. Apparently if you have a letter that follows a number, a space isn't needed... how weird, but cool!
This finds the remainder / modulus of the input integer n divided by every number from 2 up to n-1. If there is at least one number in this sequence that has no remainder, or results in 0, this means that the number is not prime. If every value in this sequence is non-zero, the value is prime. Also by definition, 1 isn't prime and so that has to be taken care of separately.
n=input();print n!=1 and=1and all(n%i for i in range(2,n)) Example Runs
I ran this in IPython:
In [40][10]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 1 False In [41][11]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 2 True In [42][12]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 3 True In [43][13]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 4 False In [44][14]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 5 True In [45][15]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 6 False In [46][16]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 7 True In [47][17]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 10 False In [48][18]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 15 False In [49][19]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 17 True In [50][20]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 20 False In [51][21]: n=input();print n!=1 and=1and all(n%i for i in range(2,n)) 30 False