I wanted to put this as comment but due to reputation restriction i have to add it as an answer. Though your code is fine, another thing to look is amount of division happening the code, Division is computationally expensive operation and as @Michael has suggested that it is redundant. So always try to minimise the multiplication and division operation in your code. You have mentioned your self as a beginner programmer, i believe it is a good practice to start familiarising your self with topics like Computational Complexity. Look [here][1] for computational complexity of mathematical functions [1]: https://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations