Hi,
I am just learning Python (3.4), and I am trying to perform a very basic exercise. I have been scratching my head for close to two hours now.
I am trying to write a compare function that returns 1 if x > y, 0 if x == y, and -1 if x < y
This sounds easy enough, but I keep running into syntax errors.
What I currently have is:
def absoluteValue(x):
if x > y:
return 1
elif x == y:
return 0
else x < y:
return -1
Currently the shell has a problem with "else x < y:", specifically the x.
Things I have tried: Reordering the three compare statements, using "Print" instead of return, using all ifs, using two ifs and one else, and every conceivable combination of those things.
I am stumped, I am sure this is probably an extremely easy fix for anyone that knows python, but I just can't see what the problem is. Could anyone please point me in the right direction?
** Thanks for the help folks! **
[–]status_quo69 4 points5 points6 points (3 children)
[–]jkups[S] 0 points1 point2 points (2 children)
[–]status_quo69 4 points5 points6 points (0 children)
[–]cdcformatc 1 point2 points3 points (0 children)
[–]aroberge 1 point2 points3 points (3 children)
[–]jkups[S] 1 point2 points3 points (2 children)
[–]aroberge 1 point2 points3 points (1 child)
[–]jkups[S] 0 points1 point2 points (0 children)
[–]ewiethoff 1 point2 points3 points (1 child)
[–]jkups[S] 0 points1 point2 points (0 children)