I recently started learning python (by which I mean, 35 minutes ago at the time of posting...) and I've wrote a few things e.g. square root generator, factorial generator, Fibonacci number generator, prime checker etc. After I wrote the prime checker, I thought I'd try modifying it so that instead of checking every number in the specified range, it would accept an input and check that one specifically.
DISCLAIMER: If I were better at Python then I would only check numbers up to sqrt(p) and I would add an option to check if it is even and not 2 then it automatically returns that it's not prime but let me walk before I run! :)
CODE:
p = input("Enter a potential prime.")
for n in range (2,p):
if p % n == 0:
print(p, "equals", n, "x", p//n, "so it isn't a prime number")
break
else:
print(p, "is a prime number.")
It works for p = 2 but that's it...
NB - Obviously the code is indented accordingly, it's just not formatted properly here.