My homework is to find the "emirp numbers" (pairs of primes like 13 ⇆ 31) up to 10,000. I can reverse the digits using [::-1]
, but I must do it with %
instead.
Here's my code. It works, but how can I reverse the digits using %
instead of [::-1]
?
counter=0;
prime_counter=0;
emirp_counter=0;
for N in range(13,9968):
i=2;
controlq=1;
while i < N/2+1 and controlq==1:
counter+=1;
if N % i == 0:
controlq=0;
i+=1;
if controlq==1:
x=int(str(N)[::-1]); # Here's the problem.
a=2;
controlw=1
while a < x/2+1 and controlw==1:
emirp_counter+=1
if x % a == 0:
controlw=0;
a+=1
if controlw==1 and (N!=x):
prime_counter+=1;
print(N,'<-- is an emirp number -->',x,);
print('TOTAL PRIME NUMBERS', prime_counter);
print('TOTAL PROCESS', emirp_counter+counter);
I just started learning Python (and programming) 1 month ago.