It is not uncommon that learners can’t implement the code correctly in their first try, but they all need to solve the errors themselves. I would suggest you to walk through your code with the maths formula provided (if any) in the description of the exercise and check for any inconsistency. If nothing is found, then run your code with some simple inputs like this post and print out any intermeidate variables like this post to check if something is not working as expected.
Good luck Simon.
Raymond