Answer to Question #348442 in Python for akash

Question #348442

write a program to find the first prime number in the given inputs


1
Expert's answer
2022-06-07T08:16:12-0400
def enter():
    list_numbers = []
    n = int(input("Enter the count of numbers: "))
    for count in range(0, n):
        list_numbers.append(int(input("Enter item {0}: ".format(count + 1))))
    return list_numbers


def isPrime(n):
    if n == 2 or n == 3:
        return True
    if n < 2 or n % 2 == 0:
        return False
    if n < 9:
        return True
    if n % 3 == 0:
        return False
    r = int(n ** 0.5)
    f = 5
    while f <= r:
        if n % f == 0:
            return False
        if n % (f + 2) == 0:
            return False
        f += 6
    return True


def findFirstPrime(list_numbers):
    for num in list_numbers:
        if isPrime(num):
            return num


res = findFirstPrime(enter())
print("The first prime number in the given inputs :", res)

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