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
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))
Comments
Leave a comment