Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

opposite return of the function

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")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading