Home > Mobile >  opposite return of the function
opposite return of the function

Time:03-17

I am doing some Python exercisses and for some reason my fucntion is returning to me opposite bool value. If statement under the function need to has "not" to work properly - can anyone explain me what am I doing wrong?

number = int(input("Enter numbers you want to check: "))


def dividers(number):
temp_tab = range(2, number)
divider = 0

for x in temp_tab:
    while number % x == 0:
        divider  = 1
        if divider > 1:
            return False
        else:
            return True


if not dividers(number):
   print("It is a prime number")
else:
   print("It is not a prime number")

CodePudding user response:

It seems like you want a function to check if a number is prime:

def is_prime(number):
    if number <= 1: return False

    for x in range(2, number):
        if number % x == 0:
            return False
    return True


number = int(input("Enter numbers you want to check: "))

if is_prime(number):
    print("It is a prime number")
else:
    print("It is not a prime number")
  • Related