Python function to check if number is prime

def is_prime(num):
    lst = []
    if num > 1:
        pass
    else:
        return False
    for number in range(0, 1000000+1):
        if str(num) in str(number):
            continue
        elif str(1) in str(number):
            continue
        elif str(0) in str(number):
            continue
        lst.append(number)
    for x in lst:
        if num % num == 0 and num % 1 == 0 and not(num % x == 0):
            return True
        else:
            return False

print(is_prime(9))

I do not know what is the problem with my code and I cannot find a solution the point of the program is to check whether the number is a prime number or not(prime number is only divisible by 1 and itself). The for loop just doesn't seem to work or something



Read more here: https://stackoverflow.com/questions/65728113/python-function-to-check-if-number-is-prime

Content Attribution

This content was originally published by Irkl1_ at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: