janos' answer is good. Let's me add a few simple independant comments on top of his solution : - Unlike C or C++, Python's modulo operator (%) always return a number having the same sign as the denominator (divisor). Thus, as D is supposed to be positive, `(Y - X) % D >= 0`. Therefore, your check could be written `if (Y - X) % D != 0` or in a more Pythonic way : `if (Y - X) % D`. - Python has a pretty cool [divmod][1] function. It computes quotient and reminder which is exactly what you want here. Your function becomes : def solution(X, Y, D): q, r = divmod(Y-X, D) if r > 0: return q + 1 return q - You could avoid the repeted `return jump` by using the ternary operator : `return jumps + (1 if (Y - X) % D > 0 else 0)`. By taking all comments into account, your code becomes : def solution2(X, Y, D): q, r = divmod(Y-X, D) return q + (1 if r else 0) It cannot really get any simpler, can it ? [1]: https://docs.python.org/2/library/functions.html#divmod