rewrite program with python