The Practice of Computing Using Python 3rd edition by Punch and Enbody
I'm new to coding and it's been like 3 weeks. This is my assignment and I can't even get a glimpse of the answer. I reckon I have to get result when I put 6 for example like,
2 is prime.
3 is prime.
4 is not prime.
5 is prime.
6 is not prime.
All I know is real basic things like while
, for
, if
, else
, break
and so on. And I have to solve this with only those.
And I cannot understand what that 'unnecessary checks' also means by. Please help.
This is my try and I know it's quite bismal.
N = int(input("Enter an int > 1:"))
k = 2
while k < N:
for i in range(2, N):
if k % i == 0:
print(k, "isn't prime!")
break
else:
k += 1
else:
print(k, "is prime!")