Question

A palindromic prime is a prime number that is also a palindrome (reads the same forwards and backwards). For example, 373 is a palindromic prime. Write a Python program, in a file called palindromic_prime.py, to display the first n primes where the value of n is obtained from the user. Output NUM_PER_LINE palindromic primes per line, where NUM_PER_LINE is assigned to 10 (note format in sample output below).

Your solution should include the following functions:

  • isPrime(number) - returns True if number is prime, False otherwise
  • isPalindrome(number) - returns True if number is a palindrome, False otherwise
  • reverse(number) - returns the reverse of number (i.e., reverse(123) returns 321)

Sample output:

How many palindromic primes should be computed?: 100
    2     3     5     7    11   101   131   151   181   191
  313   353   373   383   727   757   787   797   919   929
10301 10501 10601 11311 11411 12421 12721 12821 13331 13831
13931 14341 14741 15451 15551 16061 16361 16561 16661 17471
17971 18181 18481 19391 19891 19991 30103 30203 30403 30703
30803 31013 31513 32323 32423 33533 34543 34843 35053 35153
35353 35753 36263 36563 37273 37573 38083 38183 38783 39293
70207 70507 70607 71317 71917 72227 72727 73037 73237 73637
74047 74747 75557 76367 76667 77377 77477 77977 78487 78787
78887 79397 79697 79997 90709 91019 93139 93239 93739 94049

A palindromic prime is a prime number that is also a palindrome (reads the same forwards and backwards). For example, 373 is

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def isPrime(num):

i=2

if(num%2==0 and num!=2):

return False

while(i<num):

if(num%i==0):

return False

i=i+1

return True

def reverse(n):

rev=0

while(n>0):

dig=n%10

rev=rev*10+dig

n=n//10

return rev

def isPalindrome(num):

rev=reverse(num)

#print("rev ",rev,"num",num)

return rev==num


count=int(input("How many palindromic primes should be computed : "))

i=0

index=1

while(i<count):

if(isPrime(index) and isPalindrome(index)):

print(index,end=" ")

if(i%10==0):

print()

i=i+1

index=index+1

defisP rine(num): [GCC 4.8.2] on 1inux How any palindronic primes shauld ke computed 1 100 if(num%2#8 and num!#2) 2 35 7 11

Add a comment
Know the answer?
Add Answer to:
A palindromic prime is a prime number that is also a palindrome (reads the same forwards...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING C# AND PSUDOCODE PLEASE : A palindromic prime number is a number that is both...

    USING C# AND PSUDOCODE PLEASE : A palindromic prime number is a number that is both prime number and a palindrome number. For example, 131, 313, and 757 are palindromic prime numbers. Design (pseudocode) and implement (source code) a program (name it PalindromicPrime) to display the first 50 palindromic prime numbers, 10 per line separated by one space. The program defines the following methods: Method isPalindome() to check if a number is palindrome or not. Method isPrime() to check if...

  • A number is said to be a palindrome if it reads the same backwards as forwards​...

    A number is said to be a palindrome if it reads the same backwards as forwards​ (for example,​ 54845). How many 5​-digit numbers are​ palindromes?

  • A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...

    A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Program 4:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Program 4: A palindromic prime number is a number that is both prime number and a palindrome number. For example, 131, 313, and 757 are palindromic prime numbers. Design (pseudocode) and implement (source code) a program (name it PalindromicPrime) to display the first 50 palindromic prime numbers, 10 per line separated by one space. The program defines the following methods: Method isPalindome() to check if a...

  • A palindrome is a word, phrase, number, or other sequence of characters which reads the same...

    A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise. public class Recursion {                 public static void main(String[] args) {                                 Recursion r = new Recursion();                                 System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true                 }                 public Boolean isPalindrome(int num){                                 return false;...

  • Using python Part 3c: Custom Number Range Make a copy of Part B and update it...

    Using python Part 3c: Custom Number Range Make a copy of Part B and update it so that the user can choose to examine a specific range of numbers for prime numbers. Here's a sample running of your program: Start number: 5 End number: -5 Start and end must be positive Start number: 5 End number: 3 End number must be greater than start number Start number: 5 End number: 23 5 7 11 13 17 19 23 Part 3d:...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • PYTHON! The Sieve of Eratosthenes THANKS FOR HELP! A prime integer is any integer greater than...

    PYTHON! The Sieve of Eratosthenes THANKS FOR HELP! A prime integer is any integer greater than 1 that is evenly divisible only by itself and 1. The Sieve of Eratosthenes is a method of finding prime numbers. It operates as follows: Create a list with all elements initialized to 1 (true). List elements with prime indexes will remain 1. All other elements will eventually be set to zero. Starting with list element 2, every time a list element is found...

  • Python Program Eratosthenes of Cyrene lived approximately 275-195 BC. He was the first to accurately estimate...

    Python Program Eratosthenes of Cyrene lived approximately 275-195 BC. He was the first to accurately estimate the diameter of the earth. For several decades he served as the director and chief librarian of the famous library in Alexandria. He was highly regarded in the ancient world, but unfortunately only fragments of his writing have survived. The algorithm described for this assignment is known as the Sieve of Eratosthenes. The algorithm is designed to find all prime numbers within a given...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT