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.
A palindrome prime is a prime number that reads the same forwards or backwards. An example...
A palindrome prime is a prime number that reads the same forwards or backwards. An example of a palindrome prime is 131. Write a method with the following signature for determining if a given number is a palindrome prime. public static boolean isPallyPrime(int nVal) Note: For this assignment you are not allowed to use the built in Java class Array as part of your solution for any of these questions. Your Method signatures must be the same as given here.
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:...
A prime number is a number that is only evenly divisible by itself and 1. For...
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. Design a Boolean function called isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise. Use the...
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...
5. A prime number is a number that is only evenly divisible by itself and 1....
5. 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, how‐ ever, is not prime because it can be divided evenly by 1, 2, 3, and 6.   Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise....
Python Programming An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also...
Python Programming An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also a prime. For example, 17 and 71 are prime numbers, so 17 and 71 are emirps. Write a program that displays the first 10 emirps.
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...
C++ Create a program that checks whether a number is a prime number and displays its...
C++ Create a program that checks whether a number is a prime number and displays its factors if it is not a prime number. Console Prime Number Checker Please enter an integer between 1 and 5000: 5 5 is a prime number. Try again? (y/n): y Please enter an integer between 1 and 5000: 6 6 is NOT a prime number. It has 4 factors: 1 2 3 6 Try again? (y/n): y Please enter an integer between 1 and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT