OpenAI interview question

Refactor the following simple code