
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Check if given number is Emirp Number or not in Python
Suppose we have a number n. We have to check whether n is an Emirp number or not. We all know Emirp number is (letters of prime in backward direction) is a prime number that results in a different prime when its digits are reversed.
So, if the input is like n = 97, then the output will be True as the reverse of 97 is 79 which is another prime.
To solve this, we will follow these steps −
- if num is not prime, then
- return False
- reverse_num := reverse of num
- return true when reverse_num is prime otherwise false
Example
Let us see the following implementation to get better understanding −
def is_prime(num): if num <= 1: return False for i in range(2, num): if num % i == 0: return False return True def solve(num): if not is_prime(num): return False reverse_num = 0 while num != 0: d = num % 10 reverse_num = reverse_num * 10 + d num = int(num / 10) return is_prime(reverse_num) n = 97 print (solve(n))
Input
97
Output
True
- Related Articles
- Check if the given number is Ore number or not in Python
- Check whether the given number is Euclid Number or not in Python
- Check if a number is an Achilles number or not in Python
- Program to check whether given number is Narcissistic number or not in Python
- Check if a given number is sparse or not in C++
- Swift Program to Check if the given number is Perfect number or not
- Check if a number is in given base or not in C++
- Check if number is palindrome or not in Octal in Python
- Check if a number is Primorial Prime or not in Python
- Check whether the given number is Wagstaff prime or not in Python
- Python program to check if a number is Prime or not
- Check if a number is a Krishnamurthy Number or not in C++
- Check if a number is an Unusual Number or not in C++
- Check if a number is an Achilles number or not in C++
- Check whether a given number is Polydivisible or Not

Advertisements