How to check if a number is palindrome number or not and if it is, follow with checking if it is a prime number too.
How to check if a number is palindrome number or not and if it is, follow with checking if it is a prime number too.
For palindrome number, you can go with this algorithm:
num
)temp
)For Prime number:
temp
)2
to temp-1
using For loop temp = num
def is_palindrome():
global num
global temp
rev = 0
while (num > 0):
dig = num % 10
rev = rev * 10 + dig
num = num // 10
if (temp == rev):
print("The number is palindrome!")
else:
print("This is Not a palindrome!")
def prime_checker():
global temp
is_prime = True
for N in range(2, temp):
if (temp % N) == 0:
is_prime = False
break
if is_prime:
print("It's a prime number.")
else:
print("It's not a prime number.")
is_palindrome()
prime_checker()```
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.