To diagnose the issue with your findIt
function, you should include a debugging statement that checks the value of ar[i]
before the return statement. This is because the logic of your program relies on the comparison between x
and ar[i]
, and observing the qualities of ar[i]
during the iterations will help identify why the function misbehaves for the input value 24
.
The line to include for debugging could look something like this:
print(f"Comparing x: {x} with ar[{i}]: {ar[i]}")
This will allow you to see what ar[i]
is at each iteration of the loop and understand why the function is returning prematurely.