Python Forum
New to Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: New to Python (/thread-1058.html)



New to Python - pmauer456 - Nov-30-2016

All,

  I'd really appreciate some help here.  I'm trying to learn Python from a book and in one section they put the function you see below.  So I decided I'd go "off book" and try to make up a simple little program on my own.  From what I can read in the book this should work but I keep getting a syntax error after this part

if (checkIfPrime) == False:
with the colon highlighted. 

I've tried all kinds of permutations with no luck and I asked a friend at work (NOT a programmer but kinda like me) and he wasn't helpful either.

Any advice will be appreciated,

Thanks

Paul




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

number = int (input ("What number would you like to check to see if it's a prime number?")
             

if (checkIfPrime) == False:
    print ("The number ", number ," is not a Prime number.")
else:
    print ("Congratulations!  The number ", number ," is a Prime number.")



RE: New to Python - metulburr - Nov-30-2016

first of all the syntax error is because you are missing a closing paren on the line before it. Next you are going to want to call your function such as 
Quote:if (checkIfPrime) == False:


change to
if not checkIfPrime(YOUR_NUMBER_HERE):
you also dont need to compare to a boolean, as it returns None by default.