Writing check_digit method