Question

In: Computer Science

A number is a palindromic prime if it is a prime number as well as a...

A number is a palindromic prime if it is a prime number as well as a palindromic number (ie. it is the same number when the digits are reversed).

For example, 10301 is a palindromic prime.

Write a Python program to ask the user how many palindromic primes they would like to compute, and output the values with a maximum of 10 values per line.

Your program should include the following functions:

isPrime(number) - returns True or False

isPalindrome(number) - returns True or False

reverse(number) - returns number reversed

Sample input/output: How many palindromic primes should be computed?: 25

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

Solutions

Expert Solution

Python code screenshot:

Sample Inputs and Outputs:

Python Code to copy:

def isPrime(number): # check if number is prime or not
  for i in range(2,number):
    if(number % i) == 0: # if number is divisible by i = [2 , number) then it is not prime
      return False
  return True

def reverse(number): # find reverse of a number
  rev = 0
  while(number != 0):
    rev = rev*10 + number%10
    number = number//10 
  return rev

def isPalindrome(number): # check if number is palindrome or not
  if number == reverse(number): # if number equals its reverse then it is palindrome
    return True
  else:
    return False

def main():
  n = int(input("How many palindromic primes should be computed?: ")) # take input
  i = 2
  count = 0 # to make sure that a maximum of 10 number a printed in a line
  while n > 0:
    if(isPrime(i) and isPalindrome(i)): # check for both condition
      print(i,end = " ")
      count += 1
      if( count == 10 ): # if 10 number get printed, print newline
        print("\n")
        count = 0
      n -= 1
    i += 1

main()


    


Related Solutions

Prime Number Determines if a number is prime or not I also need the algorithm and...
Prime Number Determines if a number is prime or not I also need the algorithm and pseudocode in java.
A prime number (or prime) is a natural number greater than 1 that has no posítive...
A prime number (or prime) is a natural number greater than 1 that has no posítive divisors other than 1 and itself. Write a Python program which takes a set of positive numbers from the input and returns the sum of the prime numbers in the given set. The sequence will be ended with a negative number.
Java program Prime Numbers A prime number is a natural number which has exactly two distinct...
Java program Prime Numbers A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a java program which reads a list of N integers and prints the number of prime numbers in the list. Input: The first line contains an integer N, the number of elements in the list. N numbers are given in the following lines. Output:...
isPrime Function. A prime number is a number that is only evenly divisible by itself and...
isPrime Function. A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a function named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. The...
Prime number indicator: In this activity, you will design a circuit that indicates whether a number...
Prime number indicator: In this activity, you will design a circuit that indicates whether a number between 0 through 15 is a prime number or not. A prime number is defined as a number that can be divided only by itself and 1. By definition, the numbers 0 and 1 are not prime. The circuit must have four binary inputs A, B, C, D, and one output, G. The output signal G is true (G = 1) if the input...
A palindromic number reads the same both ways (left-to-right and right-to-left). The largest palindrome made from...
A palindromic number reads the same both ways (left-to-right and right-to-left). The largest palindrome made from the product of two 2-digit numbers is 9,009 = 91 × 99. The largest palindrome made from the product of two 3-digit numbers is 906,609 = 913 × 993. The largest palindrome made from the product of two 4-digit numbers is 99,000,099 = 9,901 × 9,999. 1. Write a function IN JAVASCRIPT to find the largest palindrome made from the product of two 7-digit...
A prime number is an integer greater than 1 that is evenlydivisible by only 1...
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided by 1, 2, 3, and 6.Write a Boolean function named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, and false otherwise. Demonstrate...
Prove or disprove each of the following statements. (a) There exists a prime number x such...
Prove or disprove each of the following statements. (a) There exists a prime number x such that x + 16 and x + 32 are also prime numbers. (b) ∀a, b, c, m ∈ Z +, if a ≡ b (mod m), then c a ≡ c b (mod m). (c) For any positive odd integer n, 3|n or n 2 ≡ 1 (mod 12). (d) There exist 100 consecutive composite integers.
A number is prime if it can be divided exactly only by 1 and itself. Here...
A number is prime if it can be divided exactly only by 1 and itself. Here is an algorithm for checking if an input number is prime: function out = isprime(m)             for j:=2 to m-1             if mod(m,j) ==0 then             return “input is not a prime”             endif             endfor             return ”input is a prime” Let n denote the size of the input m, i.e. the number of bits in the binary expression for m. What is...
Python question Recall that a prime number is an integer that is only divisible by 1...
Python question Recall that a prime number is an integer that is only divisible by 1 and itself. For example, numbers 2, 3, 5, 7, 13, 19 are prime, whereas 4, 10, 12, 100 are not. Also, recall that factors are the numbers you multiply to get another number. For example, 24 has 8 factors: 1, 2, 3, 4, 6, 8, 12, and 24. As you know, any number can be factorized into several (possibly repeating) prime factors. For instance,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT