Q1) Write a Python program to find the list of reverse of the elements in the given list would be prime number.
Input Format
[ 74, 5, 33, 79, 12, 56]
Constraints
1.If there is no prime number in the given list then print**('No prime number')**
Output Format
List of prime numbers: [74, 5, 79]
(or)
No prime number
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n %2 == 0:
return False
i = 3
while i*i <= n:
if n%i == 0:
return False
i += 2
return True
def reverse_num(n):
s = str(n)
s = s[::-1]
return int(s)
def main():
line = input()
L = eval(line)
res = []
for n in L:
if is_prime(reverse_num(n)):
res.append(n)
if res:
print('List of prime numbers:', res)
else:
print('No prime number')
if __name__ == '__main__':
main()
Comments
Leave a comment