With your updated code, an input of 3 gives a sum of 0.875. It is your original code that gives a sum of 2 for an input of 3. In any case, a single incorrect result is sufficient to prove that your implementation is incorrect.I don't know why it become like this, but when in typed in 3, it gives the result 2, which is the correct answer.