python implentation of c code practice