implementation of Turing Machine in Python