I am currently reading “How to think like a computer scientist: Learning with Python” (Green Tea Press, January 2002.)
I can’t make any define functions work. I have copied it exactly as it is in the book, but it is not working. What at I doing wrong?
Here is the code:
def printParity(x):
if (x)%2 == 0:
print (x), ("is even")
else:
print (x), ("is odd")
It just prints the (x) input rather that (x) is odd or even.
You want:
Your statement
print (x), ("is even")is actually making a tuple, as can be seen at the console: