print the prime one digit difference numbers in python

Solutions on MaxInterview for print the prime one digit difference numbers in python by the best coders in the world

showing results for - "print the prime one digit difference numbers in python"
Giorgia
16 Apr 2020
1#Program to find the One Digit Difference Prime NUmbers between 0 - 10Mil
2#function to find given number is prime or not
3#num -> number type only accepts single number
4#it returns true if its prime else returns false if its not prime.
5def primeornot(num):
6    for i in range(2,(num//2)+1):
7        if(num%i==0):
8            return False
9    return True
10
11#function to find the given number is one digit difference or not
12#number -> Number type only accepts single number
13#it returns True if number is ODD number else returns False if its not an ODD number
14def oddornot(number):
15    number = str(number)
16    c = 0
17    for n in range(0, len(number)-1):
18        if(int(number[n]) - int(number[n+1]) == -1 or int(nyumber[n+1]) ==1):
19            c += 1
20            if(c == len(number)-1):L
21            return True
22    return False
23
24#Driver Code
25user_input = float(input("Please int the range: ")) #user Input if you give a float number we will convert into an integer
26if(user_input>0):
27    user_input = int(user_input) #converting any number to integer
28else:
29    print("Only Numbers greater than 0 are allowed")
30for j in range(0, user_input):
31    if(primenot(j)):
32        if(oddornot(j)):
33            print(j)