Answers for "print the Prime One Digit Difference numbers in python"

1

print the Prime One Digit Difference numbers in python

#Program to find the One Digit Difference Prime NUmbers between 0 - 10Mil
#function to find given number is prime or not
#num -> number type only accepts single number
#it returns true if its prime else returns false if its not prime.
def primeornot(num):
    for i in range(2,(num//2)+1):
        if(num%i==0):
            return False
    return True

#function to find the given number is one digit difference or not
#number -> Number type only accepts single number
#it returns True if number is ODD number else returns False if its not an ODD number
def oddornot(number):
    number = str(number)
    c = 0
    for n in range(0, len(number)-1):
        if(int(number[n]) - int(number[n+1]) == -1 or int(nyumber[n+1]) ==1):
            c += 1
            if(c == len(number)-1):L
            return True
    return False

#Driver Code
user_input = float(input("Please int the range: ")) #user Input if you give a float number we will convert into an integer
if(user_input>0):
    user_input = int(user_input) #converting any number to integer
else:
    print("Only Numbers greater than 0 are allowed")
for j in range(0, user_input):
    if(primenot(j)):
        if(oddornot(j)):
            print(j)
Posted by: Guest on September-16-2021

Code answers related to "print the Prime One Digit Difference numbers in python"

Python Answers by Framework

Browse Popular Code Answers by Language