use built-in function with exception to solve the question
add test cases