states = ('q0', 'q1', 'q2') start = 'q0' accept = ('q0','q0') s = input() # start with the start state, use the transition function... currentState = start for currentLetter in s: # transition function in here, can only use current input symbol and # current state # big 'ol if/elseif if currentState == 'q0' and currentLetter == 'a': currentState = ?? elif currentState == 'q0' and currentLetter == 'b': currentState = ?? elif currentState == 'q1' and currentLetter == 'a': currentState = ?? elif currentState == 'q1' and currentLetter == 'b': currentState = ?? elif currentState == 'q2' and currentLetter == 'a': currentState = ?? elif currentState == 'q2' and currentLetter == 'b': currentState = ?? else: print('THIS SHOULD NOT HAPPEN') # do we accept or not doIAccept = False for x in accept: if currentState == x: doIAccept = True break # or do this doIAccept = currentState in accept if doIAccept: print("accept"); print("yes, accept") else: print("reject")