Coding the function

create the function and the calculation for the result