'finding emrips with python, what am i doing wrong?

An Emirp is a prime number whose reversal is also a prime. For example, 17 is a prime and 71 is a prime, so 17 and 71 are emirps. Write a program that prints out the first N emirps, five on each line.

Calculate the first N emirp (prime, spelled backwards) numbers, where N is a positive number that the user provides as input.

Implementation Details

You are required to make use of 2 functions (which you must write).

isPrime(value) # Returns true if value is a prime number. reverse (value) # Returns the reverse of the value (i.e. if value is 35, returns 53). You should use these functions in conjunction with logic in your main part of the program, to perform the computation of N emirps and print them out according to the screenshot below.

The general outline for your program would be as follows:

Step 1: Ask user for positive number (input validation) Step 2: Initialize a variable Test to 2 Step 3: While # emirps found is less than the input: Call isPrime with Test, and call it again with reverse(Test). If both are prime, print and increment number of emirps found. Test++ Hint - to reverse the number, turn it into a string and then reverse the string. Then turn it back into an int!

MY CODE:

n = 0
count = 0
i = 1
def isPrime(value):
    test = 2
    count = 0
    while(test < value):
        if( value % test == 0):
            count+=count
            test+=test
    if(count == 0):
        return 1
    else:
        return 0

def reverse(value):
    reverse = 0
    while(value > 0):
        reverse = reverse * 10 + (value % 10)
        value = value / 10
    return reverse

n = float(input("Please enter a positive number: "))

while(count < n):
    i+=i;
    if(isPrime(i)):
        if(isPrime(reverse(i))):
                print("i" + "\n")
                count+=count
        if((count % (5)) == 0 ):
                print("\n")

where are the mistakes?

UPDATED CODE BUT STILL NOT RUNNING:

    n = 0
    count = 0
    i = 1
    def isPrime(value):
     test = 2
    while(test < value):
        if( value % test != 0):
            test +=1
        else:
            return 0

def reverse(value):
    return int(str(value)[::-1])

i = int(input("Please enter a positive number: "))
count = 0
while(count < 5):
    if(isPrime(i)):
        if(isPrime(reverse(i))):
                print(str(i) + "\n")
                count += 1
                i += 1
        else:
            i += 1
    else:
        i +=1


Solution 1:[1]

There are a lot of issues with your code. I altered the function isPrime. There is among other no need for count here and if you want to increment test by 1 every loop use test +=1:

def isPrime(value):
test = 2
while(test < value):
    if( value % test != 0):
        test +=1
    else:
        return 0
return 1

There is an easy way to reverse digits by making value a string in reversed order and to convert this into an integer:

def reverse(value):
    return int(str(value)[::-1])

You among other have to assign the input to i. n in your code is a constant 5. You have to increment i by one in any condition and increment the count by one if i is an emirp only:

i = int(input("Please enter a positive number: "))
count = 0
while(count < 5):  
    if(isPrime(i)):
        if(isPrime(reverse(i))):
                print(str(i) + "\n")
                count += 1
                i += 1
        else:
            i += 1
    else:
        i +=1

Solution 2:[2]

    def emrip_no(num):
    i=0
    j=0
    for i in range(1,num+1):
        a=0
        for j in range(1,i+1):
            if(i%j==0):
                a+=1
    if(a==2):
        print("Number is a prime number")
        k=0
        l=0
        rv=0
        while(num!=0):
            r=num%10
            rv=(rv*10)+r
            num=num//10
        print("It's reverse is: ",rv)
        for k in range(1,rv+1):
            b=0
            for l in range(1,k+1):
                if(k%l==0):
                    b+=1
        if(b==2):
            print("It's reverse is also a prime number")
        else:
            print("It's reverse is not a prime number")

n=int(input("Enter a number: "))
emrip_no(n)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2