Answer to Question #312623 in Python for Chetan mirje

Question #312623

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

1
Expert's answer
2022-03-16T10:23:25-0400
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS