Python code for coursera Automata course