A prime Checker Code

PHOTO EMBED

Tue Sep 14 2021 11:14:21 GMT+0000 (Coordinated Universal Time)

Saved by @chisomloius ##python ##for-loop ##if-statements

## Your code should check if each number in the list is a prime number
check_prime = [26, 39, 51, 53, 57, 79, 85]

## write your code here
## HINT: You can use the modulo operator to find a facto
prime_numbers = []
counter_prime = 0
for prime in check_prime:
    if (prime % 2 == 0):
       print("{} is not a prime number".format(prime))
    elif (prime % 3 == 0):
        print("{} is not a prime number".format(prime))
    elif(prime % 5 == 0):
        print("{} is not a prime number".format(prime))
    elif(prime % 7 == 0):
        print("{} is not a prime number".format(prime))
    else:
        prime_numbers.append(prime)
        print("{} is a prime number".format(prime))
    counter_prime += 1

print("These are the prime numbers : {}".format(prime_numbers))



## Altenatively,

check_prime = [26, 39, 51, 53, 57, 79, 85]

# iterate through the check_prime list
for num in check_prime:

# search for factors, iterating through numbers ranging from 2 to the number itself
    for i in range(2, num):

# number is not prime if modulo is 0
        if (num % i) == 0:
            print("{} is NOT a prime number, because {} is a factor of {}".format(num, i, num))
            break

# otherwise keep checking until we've searched all possible factors, and then declare it prime
        if i == num -1:    
            print("{} IS a prime number".format(num))
content_copyCOPY

Write code to check if the numbers provided in the list check_prime are prime numbers. For each number, if the number is prime, the code should print that the number is a prime number. If the number is NOT a prime number, it should print that the number is not a prime number, and also print a factor of that number besides 1 and the number itself.

udacity.com