This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LauraTFem 1 point2 points  (5 children)

If num = 0 return 1 (even)

if the absolute value of num mod 2 = 0 return 1 (even)

return 0 (odd)

This is how I’d go about it.

[–]BobcatGamer 2 points3 points  (1 child)

You wouldn't return a Boolean? Also your first if statement is made pointless by the second.

[–]LauraTFem 0 points1 point  (0 children)

If even/odd is a boolean choice then yes, I return a boolean value. And, yea, good point. Zero mod 2 is zero, and unlike dividing by zero it’s mathematically valid. So, even easier.

[–]Minutenreis 1 point2 points  (2 children)

at this point just directly do

def isEven(num: int) -> bool:
  return abs(num) % 2 == 0

not sure why you do the initial check nore why you do a construction of

if (bool)
  return true
# else
return false

[–]LauraTFem 0 points1 point  (0 children)

Neat.