Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Examples:
- 13 17 31 37 71 73 ... are Backwards Read Primes
- >> 13 is such because its prime and read from right to left writes 31 which is prime too. Same for the others.
- >>pallidrome prime should not be taken
- backwardsPrime(2, 100) => [13, 17, 31, 37, 71, 73, 79, 97]
- backwardsPrime(501, 599) => [] || return empty list
- --------------------------------------------------------------------------------------------------------------------------------------
- def backwardsPrime(start,stop):
- list1=[]
- for i in range(start,stop):
- if i > 1:
- for j in list(range(2,i)):
- if(i%j==0):
- break
- else:
- reversed=int(str(i)[::-1])
- for item in range(2,reversed):
- if reversed%item==0:
- break
- else:
- if i!=reversed:
- list1.append(i)
- return list1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement