Quick question. Why result is initialized with -99 instead of 0?


The initial assignment of -99 to the result variable appears to be an arbitrary placeholder value chosen by the code author. This value has no specific meaning in the context of the code, and it doesn’t affect the final result of the function when determining whether a number is even or odd.

def even_or_odd(num)
  result = -99  # This is an arbitrary placeholder value
  result = num % 2  # This line calculates the actual result
  return result

The meaningful calculation occurs on the line where result is assigned the result of the modulo operation (num % 2). The -99 value is effectively replaced by the result of the modulo operation when the function is called with a specific num value.

So, the use of -99 in this context is arbitrary and doesn’t serve any functional purpose. It could have been initialized to 0, nil, or any other value without affecting the core logic of the function.

I hope this helps!

1 Like

Thanks a lot for your time.