number_of_digits = int(input())
prime = 0
count = 0
for num in range(1, number_of_digits):
given_input = int(input())
for b in range(2, given_input):
if (given_input % b == 0):
count += 1
else:
prime = prime + given_input
break
print(prime) ```
what is the error in my code!?
This is not close to correct. I suggest that you first try to make your program work on any single prime number. Give it a variety of prime and non-prime inputs and see if you can get it printing only primes.
Here are the first 15 primes: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
1 is not a prime number - make sure your program gets this right, even if you need to treat it as a special case.
Additional but important error:
for num in range(1, number_of_digits):
will loop one fewer time than you need. Just use range(number_of_digits).
def isPrime(n):
if(n==1):
return False
for i in range(2,int(n**0.5)+1):
if(n%i==0):
return False
return True
number_of_digits = int(input())
numbers=[]
for num in range( number_of_digits):
numbers.append(int(input()))
for num in numbers:
if(isPrime(num)):
print(num)
break