+ 1
Please help out
This is my code: #prog for twin prime no. n=int(input("Enter the range:")) for i in range (2,n-1): j=i+2 if n%i==0: if j%i==0: print(i, " and ", j , " are twin prime") Output is: 2 and 4 are twin prime While I want to print twin prime so the correct ans would be 3 and 5 are twin prime 5 and 7 are twin prime In the range of 10 Please help me out Thank you in advance
1 Respuesta
+ 4
Akanksha Keshari think about your logic..
for i= 2 to 10
First i=2, j=4 so 10%2==0 and 4%2==0 so that's why it prints 2 and 4 primes.....
Prime finding logic :
for i in range(2,n):
if n%i==0 :
print(" not prime ")
flag = false
break
try this to extend to find if flag== true, then check n+2 prime or not.
For finding this from 1 to input number, then repeat this within another loop from 1 to input..
post your try for further.. ..
hope it helps.