I've programmed for a while although right now I am getting an error I haven't gotten before that I don't believe should be there. I am writing a very simple function to determine the parity of a number, and in my first "if" statement I receive an error telling me the syntax is incorrect.
def int_parity():
a = int(input("Type an integer.")
if a % 2 == 0: #check if it's even by checking if the remainder is 0 after dividing by 2
print("That integer is even.")
elif a % 2 == 1: #check if it's odd by taking the remainder after dividing by 2
print("That integer is odd.")
else: #if it isn't even or odd, it is likely not an integer
print("That is not an integer.")
The error that I get says:
File "<ipython-input-87-f138806da879>", line 3
if (a % 2) == 0: #check if it's even by checking if the remainder is 0 after dividing by 2
^
SyntaxError: invalid syntax
What do I do?
Aucun commentaire:
Enregistrer un commentaire