write a program to accept a 5 digit number from the user and perform the following task exchange first digit with last and vice versa if both the numbers are prime and no need to exchange if both are not prime or anyone is prime
Answers
Answered by
1
def swap_digits(n):
primes = ["2", "3", "5", "7"]
digits = [n for n in list(str(n))]
if digits[0] in primes and digits[-1] in primes:
digits[0], digits[-1] = digits[-1], digits[0]
return "".join(digits)
return "".join(digits)
n = int(input("enter 5 digit num: "))
print(swap_digits(n))
Similar questions