General Motors (GM) interview question

implement a function in Python