Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to Python

  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,



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.")
    print ("Congratulations!  The number ", number ," is a Prime number.")
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.

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020