Can someone please explain why number 2 is also added to the list of prime numbers in the code below?
As the function below should only recognize a number as prime when there is at least 1 number with modulus not equal to 0.
As
2 % 0 = 0
2 % 1 = 0
That is why it should not be included, right?
def isprime(num1):
for i in range(2, num1):
if (num1 % i) == 0:
return False
return True
def getprimes(max_number):
list_of_primes = []
for i in range(2, max_number):
if isprime(i):
list_of_primes.append(i)
return list_of_primes
def main():
max_num_to_check = int(input('Enter the max limit: '))
list_of_primes = getprimes(max_num_to_check)
for i in list_of_primes:
print(i)
main()