rewrote parts of python lab4