Need help with refactoring the code in Python

Hi, I need a help with an assignment in Python. I just have basic knowledge on Python, so need help in understanding the code and refactoring it and also create a Test Plan out of it.