final version of python code