I'm trying to generate the prime palindromes between two integers (given by the user) and simply can't figure out where I'm going wrong. Please can someone explain?
Here's what I've got so far:
#Palindrome test
def palindrome(num):
str(num) == str(num)[::-1]
#Prime test (excl. 3, 5 & 7 because not palindrome)
def prime(num):
abs(num)%2 != 0
abs(num)%3 != 0
abs(num)%5 != 0
abs(num)%7 != 0
N = int(input("Enter the start point N: "))
M = int(input("Enter the end point M: "))
for x in range(N, M):
if palindrome(x) and prime(x):
print(x)
Alright, as was pointed out - there's more than one issue in the code above. I've tried again and come up with this (below), which manages to print out all the palindromes, but also includes the non-prime numbers. Where am I going wrong?
N = int(input("Enter the start point N: "))
M = int(input("Enter the end point M: "))
def palindrome(num):
return str(num) == str(num)[::-1]
def prime(x):
for x in range(N, M+1):
for y in range(2, x):
if x%y != 0:
return True
for z in range(N, M):
if palindrome(z) and prime(z):
print(z)
Thanks for all the feedback so far!