Answer to Question #303515 in Python for sruthi

Question #303515

Sample Input 1



5

1

10

4

3

2

Sample Output 1

3

Sample Input 2

4

2

3

5

7

Sample Output 2

2

can i get exact code for this to print first prime number


1
Expert's answer
2022-02-27T07:03:31-0500
def is_prime(a):
    if a == 1:
        return False
    if a % 2 == 0:
        return a == 2
    d = 3
    while d * d <= a and a % d != 0:
        d += 2
    return d * d > a
try:
    numbers = int(input("Enter number of numbers: "))
    print('='*20)
    print('Enter numbers: ')
    nums = [int(input()) for _ in range(numbers)]
    nums = [num for num in nums if is_prime(num)]
    print('='*20)
    print(nums[0])
except Exception as e:
    print('Somerthing went wrong...: ' +str(e))

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